Handy Git Commands
git config --global push.default current
same as running
git push origin head
Rebasing is a nice friend.
git pull --rebase
Can also set your default to always rebase (I don't)
git config --global pull.rebase true
Interactive rebasing on a specific amount of commits (X) in current branch
git rebase -i HEAD~X
Clean 1 line commit log
git log --pretty=oneline
Display log without merges displayed
git log --no-merges
Delete remote
git push -d <remote_name> <branch_name>
Delete local
git branch -d <branch_name>
Delete local w/ force delete if branch has not been merged
git branch -D <branch_name>
Checkout branch
git checkout <branch_name>
Reset branch to specific commit and remove untracked files
git reset --hard <commit-hash>
Update the remote to reflect the local reset
git push -f origin <branch_name>
Clean your repo of untracked files and directories
git clean -f -d
Delete local branches that have been merged in the remote
git branch --merged | egrep -v "(^\*|master|dev)" | xargs git branch -d
Delete all local branches that are not master
. Use -D
for a force deletion.
git branch | grep -v "master" | xargs git branch -d
git tag -a v1.4.0 -m 'my version 1.4.0'
Even better
git tag -a v1.4.0 (launches editor for annotated message)
Tagging a specific commit
git tag -a v1.4.0 9fceb02
Pushing a specific tag to a remote
git push origin v1.4.0
Pushing all tags to a remote
git push origin --tags
Show all tags with messages
git tag -n
Show details of tag
git show v1.4.0
Stash modified files
git stash
List stashes
git stash list
Apply and remove last stash
git stash pop
Apply last stash
git stash apply
Apply a specific stash
git stash apply stash@{2}
Remove/clear all stashes
git stash clear
Show contents of a stash
git stash show #
Show contents of file in a specific stash
git show stash@{#}:<relative path to file>
Deleting the last commit (XXXXXXXX = ID of last commit)
git push origin +XXXXXXXX^:<branch_name>
git reset HEAD^ --hard
git push origin -f
Removing a specific commit (XXXXXXXX = ID of commit to delete)
git rebase -i XXXXXXXX^
In VIM press dd to delete the commit line. Then :wq to write and quit.
git push <remote_name> <branch_name> -f
Ignore changes to a specific file, both local and upstream
git update-index --skip-worktree file-to-ignore.txt
Until you decide to allow them again with
git update-index --no-skip-worktree file-to-ignore.txt