4

I am trying to learn git using a tutorial (https://www.atlassian.com/git/tutorials/setting-up-a-repository/git-clone).

git config --global alias. From the tutorial i came to know that to create a shortcut for a Git command, the above syntax can be used. Can anyone provide me a working example for creating a shortcut for a git command without using the equal synatax as the above syntax didnt work for me.

4 Answers 4

10

The aliases you see in the article are:

[alias] st = status co = checkout br = branch up = rebase ci = commit 

They can be set with:

git config --global alias.st status git config --global alias.co checkout git config --global alias.br branch git config --global alias.up rebase git config --global alias.ci commit 
Sign up to request clarification or add additional context in comments.

Comments

5

It works fine for me. I think part of the problem is that your reading it too literally. That's not your fault; the instructions don't explain its own syntax very well. Here's what I did:

git config --global alias.hp help 

Notice how I didn't just write "alias.<alias>" or the like. The whole purpose of the config command is to actually configure how git works. The point of alias is to give all your commands like config, help, init, etc. new ways to be called upon.

In the above example, I typed right next to "alias." what I wanted the NEW command to be, and a space away on the right where it says "help" I refer to the command I want to make an alias for. I'm basically changing the "help" command so I can use it just by typing "hp". You can literally make it anything you want. I could use code like this:

git config --global alias.IMABigBaboon init 

and I can write IMABigBaboon instead of init and it will work. Try it!

Just be careful you don't name two commands the same thing. Otherwise you wind up changing the name of the previous alias. Remember; you can only have one alias for one command!

Comments

5

Open your ~/.bashrc and put below lines, i'm giving few example, you can create your own :

alias gph='git push origin master' alias gpl='git pull origin master' alias gcl='git clone' alias gcm='git commit' 

then restart your terminal.

Now you can use your commands like.

gcl https://github.com/ameyjadiye/whatsapp-analyst.git gcm -m "my commit reason" 

Comments

1

Here is a good article with some good and cool aliases
http://durdn.com/blog/2012/11/22/must-have-git-aliases-advanced-examples/

Another great resource for aliases is:
https://github.com/durdn/cfg/blob/master/.gitconfig


Some more advanced aliases

Alases can also execute functions and Os scripts.

Here is a sample:

l = "!bash -c 'source ~/.githelpers && pretty_git_log'" 

This alias for example will print out a full log tree with many options.
In this alias we use a bash script to do it.

The script src can be found here:
https://github.com/garybernhardt/dotfiles/blob/master/.githelpers

And here is the output of the script: enter image description here

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.