Nowadays git is indispensable tool for development of applications. I guess you run git command many times a day.
In this blog, I introduce how to make configuration of alias of git in order to make git command shorter.
For example, we assume you take 60 seconds to type git command a day. If we can make it 30 seconds with alias, we can save 150 seconds a week, 10 minutes a month and 2 hours a year!
Let's make config of alias!
We can make config of alias on .gitconfig. We can commit this file on remote repository but it may depend on the taste of each developers so it may better to set it on your local.How to set
Here's an example.$ vim ~/.gitconfig [user] name = kakeyang email = kakeyan****@gmail.com [core] editor = vim [alias] s = status ss = status -s sh = show
In this example, we can run commands like this below.
git s => git status
git ss => git status -s
git sh => git show
Recommendation of alias
Here's the recommendation of alias configuration.
It's possible to modify format of git log with using --pretty option.
Then you can run git l command.
Here's one more recommended alias. We can see modified files and lines with it.
Then you can run
git pull --rebase is convenient but bored to run it many times. But we just run git rb if we set this above.
This is for removing branch information on local with using prune, and to keep the remote branch information latest. This is very convenient.
7 Tips For Contributing To Open Source Projects On Github For Beginners
Alias with alias command
In order to confirm the configuration of alias, we can define alias named alias.[alias] alias = !git config --get-regexp '^alias\\.' | sed 's/alias\\.\\([^ ]*\\) \\(.*\\)/\\1\\\t => \\2/' | sortThen you can display the list of alias configs with running git alias command.
$ git alias
Show pretty logs
[alias] ta = log --graph --branches --pretty=format:'%C(yellow)%h%C(cyan)%d%Creset %s %C(green)- %an, %cr%Creset'
It's possible to modify format of git log with using --pretty option.
Then you can run git l command.
$ git l
Here's one more recommended alias. We can see modified files and lines with it.
[alias] ll = log --pretty=format:"%C(yellow)%h%Cred%d\\ %Creset%s%Cblue\\ [%cn]" --decorate --numstat
Then you can run
$ git ll
Pull which can rebase
If we use git pull command as it runs, your modified files on your local repository can be merged. If we add --rebase option, git executes not merge but rebase and we can keep the latest modified files on our local.[alias] rb = pull --rebase
git pull --rebase is convenient but bored to run it many times. But we just run git rb if we set this above.
$ git rb
Synchronize remote and local branch
We occur much difference between remote and local when we develop. In this case we can run git refresh command.[alias] refresh= !git fetch origin && git remote prune origin
This is for removing branch information on local with using prune, and to keep the remote branch information latest. This is very convenient.
Reference
This is the blog of our friend and we recomment do refer it too!7 Tips For Contributing To Open Source Projects On Github For Beginners
0 Comments:
Post a Comment