How do I alias commands in git?

0 votes
asked Mar 31, 2010 by developingchris

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?

15 Answers

0 votes
answered Mar 31, 2010 by diego-dias

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

    st = status
    ci = commit -v

Or you can use the git config alias command:

$ git config --global status 

On unix, use single quotes if the alias has a space:

$ git config --global 'commit -v'

On windows, use double quotes if the alias has a space or a command line argument:

c:\dev> git config --global "commit -v"

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

0 votes
answered Mar 31, 2010 by alan-haggai-alavi

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

git config commit

For global alias:

git config --global commit
0 votes
answered Mar 31, 2010 by nick-moore

This will create an alias st for status:

git config --add status

0 votes
answered Mar 31, 2010 by greg-bacon
$ git update
git: 'update' is not a git command. See 'git --help'.

Did you mean this?

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

$ git update
From 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.
0 votes
answered Mar 31, 2010 by matthew-rankin

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:

    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

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'
0 votes
answered Mar 24, 2012 by nicolas-gramlich

This worked for me:

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


$ git --version

git version (Apple Git-26)
0 votes
answered Mar 15, 2013 by zenout

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

0 votes
answered Mar 20, 2014 by wcc526

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:

    name = my name
    email =
    editor = vi 
    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^
    diff = auto  
    status = auto  
    branch = auto 
    autosetuprebase = always
0 votes
answered Jan 17, 2015 by ironicaldiction

Just to get the aliases even shorter than the standard git config way mentioned in other answers, I created an npm package mingit (npm install -g mingit) so that most commands would become 2 characters instead of 2 words. Here's the examples:

g a .                   // git add .
g b other-branch        // git branch other-branch
g c "made some changes" // git commit -m "made some changes"
g co master             // git checkout master
g d                     // git diff
g f                     // git fetch
g i                     // git init 
g m hotfix              // git merge hotfix
g pll                   // git pull
g psh                   // git push
g s                     // git status

and other commands would be similarly short. This also keeps bash completions. The package adds a bash function to your dotfiles, works on osx, linux, and windows. Also, unlike the other aliases, it aliases git -> g as well as the second parameter.

0 votes
answered Mar 3, 2015 by packer

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 checkout  
git config --global commit    
git config --global status    
git config --global 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
Welcome to Q&A, where you can ask questions and receive answers from other members of the community.
Website Online Counter