[TOC]
概述
别名用来帮助你定义自己的git命令。
比如你可以定义 git a 来运行 git add –all。
命令行设置
要添加一个别名, 一种方法是打开 ~/.gitconfig 文件并添加如下内容:
1 2 3 4 5
   | # mac平台下 vim ~/.gitconfig
  # Ubuntu系统 gedit ~/.gitconfig
   | 
 
Windows平台下修改
1 2 3 4 5 6 7 8
   | [alias]   ch = checkout   cm = commit   p = push   # Show verbose output about tags, branches or remotes   tags = tag -l   brs = branch -a   remotes = remote -v
   | 
 
…或者在命令行里键入:
1
   | $ git config --global alias.new_alias git_function
   | 
 
例如:
1
   | $ git config --global alias.cm commit
   | 
 
指向多个命令的别名可以用引号来定义:
1
   | $ git config --global alias.ac 'add -A . && commit'
   | 
 
修改配置文件
下面,是我设置的一些自定义的命令:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
   | [core] 	quotepath = false 	excludesfile = /home/frewen/.gitignore_global 	filemode = false 	editor = vim [alias] 		# git checkout 相关的自定义别名   	cha = checkout ./ 	ch = checkout    	# git commit 相关的自定义别名   	c = commit   	cm = commit -m   	ca = commit --amend   	st = status   	# Show verbose output about tags, branches or remotes   	tags = tag -l
    	# git branch 相关的自定义别名   	b = branch   	ba = branch -a   	# git pull 相关的自定义别名   	p  =  pull   	pr =  pull --rebase   	pm =  pull --merge
    	# git push 相关的自定义别名   	po = push origin   	pfordev       = push origin HEAD:refs/for/dev   	pfor20        = push origin HEAD:refs/for/dev_2.0   	pfor211       = push origin HEAD:refs/for/dev_2.1.1   	pmaster       = push origin master   	pdev          = push origin dev   	# git remote 相关的自定义别名   	rv = remote -v
    	# git push 相关的自定义别名   	l =  log [color] 	ui = auto [filter "lfs"] 	clean = git-lfs clean -- %f 	smudge = git-lfs smudge -- %f 	process = git-lfs filter-process 	required = true
   |