git config alias

Source: Internet
Author: User

Configure aliases

Do you always have the wrong order? Like what git status ? statusThis word is really hard to remember.

If you knock on it, it's git st git status a lot easier, and of course we are very much in favor of this lazy approach.

We just need to hit a line and tell git, and then we st 'll say status :

$ git config --global alias.st status

OK, now knock on the git st effect.

Of course, there are other orders can be abbreviated, many people use the expression, said co checkout ci commit br branch :

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

Subsequent submissions can be simply written as follows:

$ git ci -m "bala bala bala..."

--globalParameters are global parameters, which are useful for all git repositories on this computer.

In the Undo changes section, we know that the command git reset HEAD file can undo the staging area modification (unstage) and re-put it back in the workspace. Since it is a unstage operation, you can configure an unstage alias:

$ git config --global alias.unstage ‘reset HEAD‘

When you typed the command:

$ git unstage test.py

In fact, Git does this:

$ git reset HEAD test.py

Configure one git last to display the last commit information:

$ git config --global alias.last ‘log -1‘

In this way, git last you can display the most recent commit:

<[email protected]>Date:   Thu Aug 22 22:49:22 2013 +0800    merge & fix hello.py

There are even people who have been configured to do it in a lunatic way lg :

alias.lg "log --color --graph --pretty=format:‘%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset‘ --abbrev-commit"

Look at git lg the effect:

Why didn't you tell me earlier? Don't be excited, we're not trying to remember more English words!

Configuration file

When you configure Git, plus --global it works for the current user, if not, it only works for the current warehouse.

Where's the configuration file? Each repository's git configuration file is placed in a .git/config file:

$ cat .git/config [core]    repositoryformatversion = 0    filemode = true    bare = false    logallrefupdates = true ignorecase = true precomposeunicode = true[remote "origin"] url = git@github.com:michaelliao/learngit.git fetch = +refs/heads/*:refs/remotes/origin/*[branch "master"] remote = origin merge = refs/heads/master[alias] last = log -1

Alias is in the [alias] back, to remove the alias, directly delete the corresponding line.

The current user's git configuration file is placed in a hidden file in the user's home directory .gitconfig :

$ cat .gitconfig[alias]    co = checkout    ci = commit    br = branch    st = status[user]    name = Your Name    email = your@email.com

Configuration aliases can also directly modify the file, if the wrong, you can delete the file re-configuration through the command.

Summary

Configure git with an alias so that you can enter a command to steal a lazy. We encourage laziness.

git config alias

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.