First you start the bisect
git bisect start
Then you mark good and bad refs
git bisect good v2.6.18
git bisect bad master
and start checking good and bad refs
git bisect good/bad
and when the culprit is found
git bisect reset
git config --global push.default matching
git config --global user.name "Xavier Noria"
git config --global user.email "[email protected]"
git config --global push.default upstream
git config --global color.ui auto
git config --global color.diff.whitespace "red reverse"
git config --global pull.rebase true
git config --global diff.compactionHeuristic true
git config --global alias.lg "log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --"
echo -e '\n\n\n' > ~/.commit.template && git config --global commit.template ~/.commit.template
echo .idea > ~/.gitignore && git config --global core.excludesfile ~/.gitignore
By definining
*.rb diff=ruby
*.gemspec diff=ruby
in .gitattributes some commands get smarter:
git diff
git log -p -W
git grep -p
git log -L:new_constants_in:activesupport/lib/active_support/dependencies.rb
I committed something by error and want to undo it without a revert patch and keeping the working directory as it is. For example I added some hunks selectively and then did a commit -a by error:
git reset HEAD^
I want to undo everything local, all commits and all changes to files:
git reset origin/master --hard
Check what you are about to push, remove -p to not include diffs:
git log -p origin/master..master
I have done some changes, they are not added/commited, and I want to undo everything:
git checkout -- .
I want to know when a certain file was deleted:
git log --diff-filter=D -- path/to/file
Publish a local branch to the origin remote:
git push origin newfeature
Rewrite history of a feature branch:
git rebase -i original_branch
Abort a cherry-pick:
git reset --merge
See what's new in docrails:
git rev-parse HEAD # => S1 (before merging)
git rev-parse HEAD # => S2 (after merging)
git rev-list S1..S2 # to get a list of the new commits
Prune remotes that were deleted in origin:
git remote prune origin
List all merged branches:
git checkout stable
git branch -a --merged
Then, for each local branch you can:
git branch -d name_of_local_branch
and for each remote branch:
git push origin :name_of_remote_branch
Sergio's alias:
alias git-atpc='git branch --merged | grep -v "^*" | xargs git branch -d'
Index file corrupt:
rm -f .git/index
git reset
Tagging:
git tag v1.0
git push origin v1.0
Merge pull request at repo, branch name:
git pull https://[email protected]/gregolsen/rails.git extended_beginning_of_week
Track a remote branch:
git checkout -t origin/3-1-stable
git checkout --track -b <local branch> <remote>/<tracked branch>
List the name of the files that were changed by a certain commit:
git show --name-only --pretty=format: SHA1
See the contents of a file at a certain SHA1:
git show SHA1:path/to/file/relative/to/the/root
Rename branch (old_branch
defaults to the current branch):
git branch -m old_branch new_branch
Squashed merges:
git merge --squash branch
Show differences from different:
git diff mybranch master -- myfile.cs
Branch from a tag:
git checkout -b newbranch v1.0
Rename branch, defaults to the current branch name:
git branch -m [oldname] newname