Wednesday, December 12, 2012

Git reference command listing

This post will be updated to reflect common used GIT command
Replace 'value' with yours.

# GIT clone repo
git clone 'git repo'

# GIT remote information
git remote -v

# GIT commit
git commit -m 'comment'

# GIT checkout
git checkout -b 'branchname'

# GIT checkout from remote
git checkout -b 'branchname' origin/'branchname'

# GIT checkout branch with tag
git checkout -b 'branchname' 'tag_name'

# GIT create branch
git branch 'branchname'

# GIT list branches
git branch

# GIT list tag
git tag

# GIT create tag
git tag -a 'tag number' -m 'comment'

# GIT remove local tag
git tag -d 'tag number'

# GIT remove remote tag
git push 'remote repo' :refs/tags/'tag number'

# GIT push
git push 'remote repo' 'local branch':'remote branch'

# GIT push tags to remote
git push 'remote repo' --tags //e.g., git push origin --tags

# GIT merge
git merge 'from branch'


If you want to revert changes made to your working copy, do this:
git checkout .
If you want to revert changes made to the index (i.e., that you have added), do this:
git reset
If you want to revert a change that you have committed, do this:
git revert ...
add changes including deletion, etc.
git add -u
Remove added changes
git rm -r --cached .
=================================================
Add command alias to git in '.gitconfig' file in your $HOME directory.
[alias]
  co = checkout
  ci = commit
  st = status
  br = branch
  hist = log --pretty=format:\"%h %ad | %s%d [%an]\" --graph --date=short
  type = cat-file -t
  dump = cat-file -p

Getting hashes for the previous versions

git hist


$ git hist
* fa3c141 2011-03-09 | Added HTML header (HEAD, master) [Marina Pushkova]
* 8c32287 2011-03-09 | Added standard HTML page tags [Marina Pushkova]
* 43628f7 2011-03-09 | Added h1 tag [Marina Pushkova]
* 911e8c9 2011-03-09 | First Commit [Marina Pushkova]

git checkout  e.g., git checkout 911e8c9

Returning to the latest version in the master branch

RUN:


git checkout development