Useful GIT Commands and Aliases

By Sam Deering

Here is a reference list of some useful GIT commands which I use including GIT Aliases commands. If you know of or use any which are not here please post a comment so I can add them to help others! :)

GIT Bash

GIT Bash for Windows (formerly known as GitWin) is shell command line tool for Windows users. It is essentially a Windows port of GNU bash “Minimalist GNU for Windows” (see msysgit projects website for more details).
Download GIT Bash

Useful GIT Commands

Show all branches.

$ git branch --all


Load GITK (Generalized Interface Toolkit) Good for seeing what changes have been made and who by in a nice interface.

$ gitk


Add (if applicable) and commit changes with a message.

git commit -a -m "msg"

Search the tree contents for specific phrase and filetype. ie find the word “CSS” in all .js files.

git grep "css" -- *.js

Create a zipped backup of the current branch.

$ git archive --format=zip master^>

View local GIT config.

$ cat .git/config

Useful GIT Alias Commands

GIT Alias Commands can save you heaps of time typing in long-winded commands into your GIT CMD. They basically map a long command into whatever shorthand version you wish. They also can be configured to prettify/colorify your results. Official post on git alias commands. Also see: Must Have Git Aliases: Advanced Examples.

Show a pretty git log history.

$ git config --global alias.history "log --abbrev-commit --pretty=oneline --graph --decorate"
usage: $ git history


Show the last commit.

$ git config --global alias.last 'log -1 HEAD'usage: $ git last
usage: $ git last

Reset to state of your last commit.

$ git config --global alias.resetlast 'reset --hard HEAD'
usage: git resetlast

Free Guide:

7 Habits of Successful CTOs

"What makes a great CTO?" Engineering skills? Business savvy? An innate tendency to channel a mythical creature (ahem, unicorn)? All of the above? Discover the top traits of the most successful CTOs in this free guide.

No Reader comments

Because We Like You
Free Ebooks!

Grab SitePoint's top 10 web dev and design ebooks, completely free!

Get the latest in JavaScript, once a week, for free.