Git - bootstraponline/meta GitHub Wiki
-
o ~/.gitconfiglook under[lfs] - Review output of
git lfs env
git ls-files | grep -i "test_runner/*" | xargs wc -l
git rev-list --left-right --count master...dockerfile-
0 14- means 0 commits behind, 14 commits ahead of master. - https://stackoverflow.com/a/27940027
git config --global core.editor "code --wait"
git config --global pager.branch cat
Uninstall LFS on select CI jobs to reduce the bandwidth overhead associated with a monorepo workflow. Every git clone doesn't need all LFS files.
- script:
inputs:
- content: |
#!/usr/bin/env bash
set -e
echo "" > `which git-lfs`
echo "Git LFS disabled"
title: Disable Git LFSRemoving files is a pain. It's better to have a white list of only the important large files, instead of globbing entire directories.
$ git lfs uninstall
$ code ~/.gitattributes and remove tracking rules
$ git lfs ls-files
98420079ff * path/to/some.jar
$ touch path/to/some.jar
$ git commit -am "Removed files from git LFS tracking"
$ git lfs install
- Delete the repo from github
-
git branch --allList all branches. -
git branch -rD origin/pactPOCJavaRemove branches containing the commits git reflog expire --expire=now --allgit gc --prune=now-
git log 48ca973d2c421184de5730fb1b60e9b5fdfc7d8aEnsure bad commit is gone - https://help.github.com/articles/removing-sensitive-data-from-a-repository/
No context with leading +/- removed.
git diff -U0 --color-words --no-color > diff.txt
git checkout master
git --no-pager branch | grep -v \* | xargs git branch -D
-X can be theirs or ours
git rebase -s recursive -X ours origin/master# ~/.gitconfig
[alias]
ro = !/bin/bash -c ~/ro.sh#!/usr/bin/env ruby
# ~/ro.sh
repo_name = %x[git remote get-url origin].match(/\/[^\/]+.git/).to_s
`git remote remove origin`
`git remote add origin [email protected]:bootstraponline#{repo_name}`
puts `git remote -v`--
Track repo's master branch as a submodule.
git submodule add -b master [email protected]:USER/REPO.git
git submodule update --init --recursive --remote--
Auto fixup (add to ~/.gitconfig). git f will automatically commit any changes and squash them into the previous commit retaining the commit message of the previous commit.
[alias]
f = "!sh -c '(git add . ; git commit --amend -C HEAD)' -"
--
Clean merging (from http://stackoverflow.com/a/2763118)
git checkout better_branch
git merge --strategy=ours --no-commit master
git commit # add information to the template merge message
git checkout master
git merge better_branch # fast-forward master up to the merge
--
Update all submodules according to remote tracking branch.
git submodule update --remote
--
Change / rename file name only.
git mv -f README.md readme.md
--
git reset --soft head~2; git commit -am "auto squashed"--
Remove commit id from history without interaction.
git rebase --onto commit_sha1^ commit_sha1--
Replace 'pick' with 'f' in vim
:%s/pick /f /g--
Unstage and delete files.
git revert /path/to/file*
git checkout -- .--
Ignore changes in a submodule. Add ignore = all
# open .gitmodules
[submodule "my_module"]
path = my_module
url = [email protected]:example/my_module.git
ignore = all--
Checkout individual file one commit behind.
git checkout HEAD^1 android/adb.js
Two commits behind.
git checkout HEAD~2 android/adb.js
--
Rebase upstream master onto local master.
git pull --rebase up master--
Update submodules.
git submodule foreach git pull origin master--
Reset author to yourself.
git commit --amend --reset-authorReset author to someone else.
git commit --amend --author "username <[email protected]>"--
Rename tag v0.0.9 to v0.0.09.
git tag v0.0.09 v0.0.9
git tag -d v0.0.9
git push origin v0.0.09
git push origin :v0.0.9--
Fix deleted file not staged.
git add -u
--
Reset local branch with remote.
git remote add b [email protected]:bootstraponline/appium.git
git fetch b
git reset --hard b/reconnect
--
$ git --version
git version 1.8.1.4
--
Disable blinking cursor in MacVIM.
:set gcr=a:blinkon0
--
Push local master to remote clean branch.
git push origin master:clean
--
Rename patch-1 branch for pull request and delete the old branch.
git fetch origin patch-1
git checkout patch-1
git branch -m patch-1 reset_android
git push origin reset_android
git push origin :patch-1--
Delete a bunch of remote branches.
$ git branch --remote
b = %(origin/branch1
origin/branch2
)
b.each_line { |l| puts 'git push origin :' + l.strip.chomp + ";\\ \n" }--
Update date from StackOverflow
GIT_COMMITTER_DATE="`date`" git commit --amend --date "`date`"
--
Push current branch by default (avoids need for git push -u origin branch_name).
git config --global push.default current
git branch --set-upstream master origin/master
Text width in vim (wraps on space) ~/.vimrc
:set tw=80
:set formatoptions=tcq
Stop ruby.
killall -v ruby -s SIGKILL
Cherry pick one commit from a pull request.
git remote add pr git://github.com/npisenti/gollum.git
git fetch pr
git cherry-pick ba8dd5e4bca08efa7b73987a266f74a12ca3fe5c
# we could also checkout pr
git checkout pr/master
git < 1.7.9 Git pull and auto rebase
git config --global branch.autosetuprebase always
git >= 1.7.9 pull.rebase
git config --global pull.rebase true
List all tags, create a lightweight tag, show a tag, then push to origin.
git tag
git tag v1.0
git show v1.0
git push origin v1.0
Fix confused git pull.
git config branch.master.remote origin; \
git config branch.master.merge refs/heads/master;
git config --global core.editor "gedit -w -s"
Redo a commit before it has been pushed.
git reset --soft HEAD^
Revert a failed merge.
git revert -m 1 20dd0816a6
Stash current changes, delete last 3 commits, and then commit current changes.
git stash
git reset --hard HEAD~3
git stash pop
Add only empty files to a commit:
git ls-files --deleted | xargs git rm
Create empty branch java:
git symbolic-ref HEAD refs/heads/java
Squash commits in a pull request.
# Squash the 3 most recent commits.
# Change 'pick, pick, pick' to 'pick, s, s'
# or use f to discard the commit message
# Ctrl + \ in nano will open search and replace (pick -> s)
git rebase -i HEAD~3
git push --force
http://gitready.com/advanced/2009/02/10/squashing-commits-with-rebase.html
Save current changes, pull from upstream, restore changes, and clear the stash.
git stash save
git pull
git stash pop
git stash clear
How to revert a failing pull request:
git revert --no-edit -m 1 HEAD
Updating submodules.
git submodule update --init
git log --format='%aN <%aE>' | sort -u
Amending.
git commit --amend -m "New msg."
Override branches for clean history in pull requests. Example overrides try1 with try2. Push using git push -f origin try1.
# git branch => on try2
git branch -f try1
Rebase to update an upstream branch on a local fork.
git remote add upstream git://github.com/github/gollum.git
git fetch upstream
git rebase upstream/master
Commands and descriptions based on Quicksilver's workflow.
-
Fork
https://github.com/github/gollumby clicking the Fork button. -
Clone your fork.
git clone [email protected]:bootstraponline/gollum.git
cd gollum -
Add upstream.
git remote add upstream [email protected]:github/gollum.git -
Rebase master branch to upstream as upstream changes.
git pull --rebase upstream master -
Create new branches from master for each work item.
git checkout -b workBranch master -
Commit work to the branch.
git add .
git commit -am "Add feature." -
Rebase branches to master.
git checkout workBranch
git rebase master -
Push branch to github.
git push origin workBranch
Orgit pushif the branch is already checked out. Note that git push will push all branches, including master. -
Submit pull requests from branches and delete when no longer needed.
Note that GitHub will not allow deleting master branch if it's set as default.
git push origin :workBranch
git branch -D workBranch
Useful commands:
git reset --hard
git push --force
git branch
From git's documentation:
In other words, "git push --force" is a method reserved for a case where you do mean to lose history.
Create a new branch based on upstream.
git remote add upstream https://github.com/github/gollum.git
git fetch upstream
git checkout -b newBranch upstream/master
Force clean:
git clean -dfx
Force clean dry run:
git clean -dfxn
git config --global color.ui "auto"
git config --global alias.lg "log --graph --decorate --oneline"
Command from sant0sk1
git lg
Set name and email.
git config --global user.email "spam@email"
git config --global user.name "my name"--
Use Sublime Text as the default git editor.
git config --global core.editor "/Applications/Sublime\ Text.app/Contents/SharedSupport/bin/subl -n -w"
--
global ignore
Add to ~/.gitconfig
[core]
excludesfile = ~/.gitignore
--
Delete all remote branches in one command.
# ruby
branches = `git ls-remote --heads`.split("\n").map { |b| b.split('/').last.strip}.join(' ')
cmd = "git push origin --delete #{branches}"
puts cmd
`#{cmd}`