Last active
September 3, 2015 22:10
-
-
Save webplumbr/3a6c109a6b632c0ca3e3 to your computer and use it in GitHub Desktop.
A quick reference to git commands
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# to add a local git branch | |
git branch <branch-name> | |
# switchover to a branch | |
git checkout <branch-name> | |
# merge trunk (master) with a branch | |
git checkout <branch-name> | |
git merge master | |
# to add a remote git branch | |
git checkout <branch-name-to-be-added> | |
git push origin <branch-name-to-be-added> | |
# deleting a local and remote branch | |
git branch --delete <branch-name> | |
(or) | |
git branch -d <branch-name> | |
git push origin --delete <branch-name> | |
# list all branches (local as well as remote) | |
git branch -a | |
# | |
# in order to completely undo a local commit | |
# | |
git reset --hard HEAD~1 | |
# if you keep doing the above undo commit it will keep revert to the previous one | |
# refer: http://stackoverflow.com/a/6866485 | |
# | |
# creating a patch file based on last 4 commits | |
# refer: http://ariejan.net/2009/10/26/how-to-create-and-apply-a-patch-with-git/ | |
# | |
git format-patch -4 --stdout > name.patch | |
# applying the patch to existing checkout | |
git apply name.patch | |
# check if the patch works fine (dry-run) | |
git apply --check name.patch | |
# check the difference between two versions of a file | |
git diff ef1234d ab542e3 -- path/to/file | |
git diff ab5432e HEAD -- path/to/file | |
(or) | |
git diff ab5432e..HEAD path/to/file | |
# adding an alias | |
git config --global alias.co checkout | |
# removing a global alias | |
git config --global --unset alias.co | |
# list all configuration data | |
git config --list | |
# to make meld as the diff view tool | |
git config --global diff.external /your/script/path/meld_diff.sh | |
# contents of meld_diff.sh (from above) | |
#!/bin/sh | |
meld $2 $5 | |
# store your temporary work in buffer | |
git stash | |
# list stored work in buffer | |
git stash list | |
# delete a particular key (in this case: 2) from buffer | |
git stash drop stash@{2} | |
# apply a particular key from buffer | |
git stash apply stash@{1} | |
# or just apply stashed content | |
git stash apply | |
# pruning remote repository | |
git remote prune origin | |
# dry-run remote prune | |
git remote prune origin --dry-run | |
# to get the number of commits by committers over a specified period | |
git log --all --since="30 days ago" | git shortlog -ns |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment