Created
May 10, 2012 15:55
-
-
Save jeremyharris/2654088 to your computer and use it in GitHub Desktop.
A small collection of useful git commands for beginners.
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
# This is a handful of git commands I use on a daily basis, some of | |
# which are pretty basic, some of which took a little research to | |
# figure out how to do (so hopefully this is a time saver). It's | |
# by no means an exhaustive list as git is really freaking robust. | |
######################## | |
# logs | |
######################## | |
# unmerged differences between dev and master (not including extra master commits) | |
$ git log master...dev | |
# unmerged differences between dev and master (including extra master commits) | |
$ git log master..dev | |
# nice visual changelog (thanks @jperras) | |
# add this alias | |
$ git config --global alias.lg "log --decorate --stat --graph --pretty=format:'%C(yellow)%h%Creset (%ar - %Cred%an%Creset), %s%n'" | |
# then from now on | |
$ git lg | |
######################## | |
# working | |
######################## | |
# amend last commit | |
$ git commit --amend | |
# stash changes for later (use -u to store files not in the index) | |
$ git stash save "Working on this feature" | |
# view a diff of that stash | |
$ git show stash@{0} | |
# store portions of a changed file in the index | |
$ git add -p | |
# remove portions of a changed file from the index | |
$ git reset -p | |
# after deleting or renaming a ton of files, remove them all from the index | |
$ git rm `git ls-files -d` | |
# view a diff of files in the index | |
$ git diff --cached | |
######################## | |
# branches | |
######################## | |
# create and checkout a new branch | |
$ git checkout -b newbranch | |
# remove a branch (locally and remotely) | |
$ git branch -d newbranch | |
$ git push origin :newbranch |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment