Sign up ×
Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them, it only takes a minute:

I saw a screencast where someone had gotten

git st
git ci

to work. When I do it I get an error asking me if I meant something else.
Being a git newb, I need to know what you have to do to get this done?

share|improve this question

9 Answers 9

up vote 423 down vote accepted

Basically you just need to add lines to ~/.gitconfig

[alias]
    st = status
    ci = commit -v

Or you can use the git config alias command:

$ git config --global alias.st status 
$ git config --global alias.ci 'commit -v'

The alias command even accepts functions as parameters. Take a look at aliases.

share|improve this answer
46  
I highly recommend you use git config --global to place the aliases in ~/.gitconfig instead of .git/config for your current repository. – Jefromi Mar 31 '10 at 14:56
1  
I agree! ... I will edit my answer – Diego Dias Mar 31 '10 at 14:58
16  
I prefer settings st to status -s (short status) – hasen Mar 31 '10 at 15:59
15  
This is really awesome. I have been looking for this. Just a heads up, if you have a command with spaces you should use ' like git config --global alias.sr 'svn rebase' – Amir Raminfar Dec 1 '11 at 19:39
1  
Just another heads up, if you're using Git on Windows command line, then you will need to use double quotes " instead of single quotes when adding command with spaces, e.g. git config --global alias.ci "commit -v" – ABVincita Aug 6 at 5:01

Follwing are the 4 git shortcuts or aliases youc an use to save time.

Open the commandline and type these below 4 commands and use the shortcuts after.

git config --global alias.co checkout  
git config --global alias.ci commit    
git config --global alias.st status    
git config --global alias.br branch  

Now test them!

$ git co              # use git co instead of git checkout
$ git ci              # use git ci instead of git commit
$ git st              # use git st instead of git status
$ git br              # use git br instead of git branch
share|improve this answer

I think the most useful gitconfig is like this,we always use the 20% function in git,you can try the "g ll",it is amazing,the details:

[user]
    name = wcc526
    email = 949409306@qq.com
[core]  
    editor = vi 
[alias]
    aa = add --all
    bv = branch -vv
    ba = branch -ra
    bd = branch -d
    ca = commit --amend
    cb = checkout -b
    cm = commit -a --amend -C HEAD
    ci = commit -a -v
    co = checkout
    di = diff
    ll = log --pretty=format:"%C(yellow)%h%Cred%d\\ %Creset%s%Cblue\\ [%cn]" --decorate --numstat
    ld = log --pretty=format:"%C(yellow)%h\\ %C(green)%ad%Cred%d\\ %Creset%s%Cblue\\ [%cn]" --decorate --date=short --graph
    ls = log --pretty=format:"%C(green)%h\\ %C(yellow)[%ad]%Cred%d\\ %Creset%s%Cblue\\ [%cn]" --decorate --date=relative
    mm = merge --no-ff
    st = status --short --branch
    tg = tag -a 
    pu = push --tags
    un = reset --hard HEAD  
    uh = reset --hard HEAD^
   [color]  
    diff = auto  
    status = auto  
    branch = auto 
   [branch]  
    autosetuprebase = always
share|improve this answer
    
how do you set this up? what do you put where to make this so? – ahnbizcad Aug 25 at 5:57

It is given here Aliases.Even there are great answers here, I added this because it differs in windows and linux

share|improve this answer

This worked for me:

bco = "!f(){ git branch ${1} && git checkout ${1}; };f"

on:

$ git --version

git version 1.7.7.5 (Apple Git-26)
share|improve this answer
1  
you could also do: git config --global alias.bco 'checkout -b'. Then you could do: git bco new-branch. :) – Russell Feb 12 '13 at 22:53
2  
I like git cob. reminds me of summer, as in corn on the cob. actually a great word we don't think about enough... cob that is – mtpain Feb 26 '14 at 18:22
    
In case this is the first time anyone other than me has seen a git alias command starting with !, note that Since version 1.5.0, Git supports aliases executing non-git commands, by prefixing the value with "!" (ref) – Sam Aug 15 '14 at 11:13

As others have said the appropriate way to add git aliases is in your global .gitconfig file either by editing ~/.gitconfig or by using the git config --global alias.<alias> <git-command> command

Below is a copy of the alias section of my ~/.gitconfig file:

[alias]
    st = status
    ci = commit
    co = checkout
    br = branch
    unstage = reset HEAD --
    last = log -1 HEAD

Also, if you're using bash, I would recommend setting up bash completion by copying git-completion.bash to your home directory and sourcing it from your ~/.bashrc. (I believe I learned about this from the Pro Git online book.) On Mac OS X, I accomplished this with the following commands:

# Copy git-completion.bash to home directory
cp usr/local/git/contrib/completion/git-completion.bash ~/

# Add the following lines to ~/.bashrc
if [ -x /usr/local/git/bin/git ]; then
    source ~/.git-completion.bash
fi

Note: The bash completion will work not only for the standard git commands but also for your git aliases.

Finally, to really cut down on the keystrokes, I added the following to my ~/.bash_aliases file, which is sourced from ~/.bashrc:

alias gst='git status'
alias gl='git pull'
alias gp='git push'
alias gd='git diff | mate'
alias gau='git add --update'
alias gc='git commit -v'
alias gca='git commit -v -a'
alias gb='git branch'
alias gba='git branch -a'
alias gco='git checkout'
alias gcob='git checkout -b'
alias gcot='git checkout -t'
alias gcotb='git checkout --track -b'
alias glog='git log'
alias glogp='git log --pretty=format:"%h %s" --graph'
share|improve this answer
    
For linux, I did this to get the git-completion.bash stuff: blogs.oracle.com/linuxnstuff/entry/… – Duncan Lock Mar 9 '12 at 15:25
    
awesome thanks @Matthew Rankin – Max MacLeod Jul 15 '13 at 10:21
4  
If you use zsh, the excellent oh-my-zsh suite contains a plugin with all those "standard" git aliases - github.com/robbyrussell/oh-my-zsh/blob/master/plugins/git/… -- for bash, have a look at github.com/revans/bash-it – jobwat Aug 26 '13 at 0:22
    
noob question: what does it mean to "be sourced from" ~/.bashrc file? – ahnbizcad Aug 25 at 6:27
1  
@ahnbizcad: See tldp.org/HOWTO/Bash-Prompt-HOWTO/x237.html – Matthew Rankin Aug 25 at 15:38
$ git update
git: 'update' is not a git command. See 'git --help'.

Did you mean this?
    update-ref

$ git config --global alias.update 'pull -v'

$ git update
From git://git.kernel.org/pub/scm/git/git
 = [up to date]      html       -> origin/html
 = [up to date]      maint      -> origin/maint
 = [up to date]      man        -> origin/man
 = [up to date]      master     -> origin/master
 = [up to date]      next       -> origin/next
 = [up to date]      pu         -> origin/pu
 = [up to date]      todo       -> origin/todo
Already up-to-date.
share|improve this answer

You need the git config alias command. Execute the following in a Git repository:

git config alias.ci commit

For global alias:

git config --global alias.ci commit
share|improve this answer

This will create an alias st for status:

git config --add alias.st status

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.