Useful GIT Commands and Aliases

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

git-branch-all

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

$ gitk

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^>backup-10-04-2013.zip

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

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 book: Jump Start HTML5 Basics

Grab a free copy of one our latest ebooks! Packed with hints and tips on HTML5's most powerful new features.

No Reader comments

Comments on this post are closed.