Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating aliases for Git branch names

Suppose I have the following branches in git:

  • master
  • release-2014-11-02-some-long-text

I would like to easily switch between those to, like this:

git checkout devel # checkout to master
git checkout release # checkout to the branch release currently points/aliases to, in this case:  release-2014-11-02-some-long-text (I would like to change this alias from time to time)

How can I do that in Git?

like image 408
syntagma Avatar asked Nov 15 '14 08:11

syntagma


People also ask

How do I make an alias command in git?

It is important to note that there is no direct git alias command. Aliases are created through the use of the git config command and the Git configuration files. As with other configuration values, aliases can be created in a local or global scope.

How can add a git URL as an alias?

Add git alias The simplest way to add a git alias is by running a command to add the alias to the git global configuration file. For example, running the command git config --global alias. hist "log --pretty=format:'%h %ad | %s%d [%an]' --graph --date=short" will add the alias git hist .


1 Answers

You can try using git symbolic-ref (as mentioned in "Is it possible to alias a branch in Git?"):

git symbolic-ref refs/heads/devel   refs/heads/master
git symbolic-ref refs/heads/release refs/heads/release-2014-11-02-some-long-text

You can find a similar example in this gist.

like image 63
VonC Avatar answered Sep 23 '22 03:09

VonC