Skip to content

Git Common Commands

fredchu edited this page May 15, 2012 · 1 revision

Git Common Commands

set username

$ git config --global user.name ben

set user email

$ git config --global user.email [email protected]

set editor

$ git config --global core.editor mate

set diff tool

$ git config --global merge.tool mate

set color

$ git config --global color.diff auto
$ git config --global color.status auto
$ git config --global color.branch auto

list configs

$ git config --list

help

$ git help <verb>

initializing a repository in an existing directory

$ git init <dir name>

ignoring files

$ mate .gitignore

keep empty folder

$ mate .gitkeep

clone a repository

  • syntax
$ git clone <url>
$ git clone git://github.com/schacon/grit.git
  • clone from github
$ git clone git://github.com/schacon/grit.git mygrit

checking the status of files

$ git status

add or update file

  • syntax
$ git add <expression>
  • add or update all file under the directory
$ git add .
  • add or update all file end with .c
$ git add *.c
  • only update exist file
$ git add -u
  • add or update index.php and register.php
$ add index.php register.php

commit staging files to local repo

  • syntax
$ git commit <option>
  • commit files with description "blah"
$ git commit -m "blah"

remove file from repo and directory

  • syntax
$ git rm <file name>
  • remove staging file
$ git rm --cached <file name>
  • change file name
$ git mv <old_file> <new_file>

compare working tree with staging area

$ git diff

compare staging area with repo.

$ git diff --cached

compare working tree with repo.

$ git diff HEAD

reset files from staging area to untagging or untracked

$ git reset HEAD <file name>

reset files from unstaging to original status ( as pull from repo )

$ git checkout <file name>

create tag

$ git tag -a v1.0.0 -m "Creating the first official version."

show tag info

$ git show v1.0.0

show all tags

$ git tag -l

show some tags

$ git tag -l 'v1.4.*'

tag old commit

$ git tag -a v1.2 7c5f24d

push tag to remote

$ git push origin v1.0.0

push all tags

$ git push origin --tags

delete tag

$ git tag -d v1.0.0

delete remote tag

$ git push origin :refs/tags/v1.0.0

create new branch

$ git branch new_branck

edit wrong msg

$ git rebase -i <commit number>