Skip to content

Instantly share code, notes, and snippets.

@mmiliaus
Created May 14, 2011 17:59
Show Gist options
  • Save mmiliaus/972444 to your computer and use it in GitHub Desktop.
Save mmiliaus/972444 to your computer and use it in GitHub Desktop.
Git in 20 minutes
=config
# use colors in git output
git config --global color.ui true
=basics
git branch -d test //delete branch
=.gitignore file
*a # ignore all with .a ext
!lib.a # except file "lib.a"
config/ # do not index config/ dir
doc/*.txt # ignore doc/notes.txt, but not doc/sever/arch.txt
# stages all tracked files and commits, no need to 'add' them first
git commit -a -m 'msg'
git status
# commit history, last 2 commits(-2) with 'diff' displayed(-p)
git log -p -2
# SHA-1 key + msg
git log --pretty=oneline
# check out changes in origin/master that are not in the master
git log origin/master --not master
# check if file is tracked
git ls-files file_name --error-unmatch
=branches
# create a branch from particular commit
git branch b_name ladslksad2lk2lk522333
=undo
# remove test.rb from staged files list
git reset HEAD test.rb
# revert changes to the last committed state
git reset --hard HEAD
# revert hello.rb to the state in index
git checkout -- hello.rb
# revert hello.rb to the last commit state
git checkout HEAD hello.rb
# creates a new commit that undos last commit
git revert HEAD
=remote
# add new remote repository and name it "origin"
git remote add origin git@github.com....:mmiliauskas/test.git
# fetch from remote
git fetch origin # it goes to remote, checks if there is some changes that I don't have, downloads them and stores into "origin/master" branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment