Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a shortcut for git branch name?

Tags:

git

I tend to have long branch names for git (e.g., step110_create_search_engine_to_replace_google).

How should I refer to it simply as step110 in checkout/commit statements?

like image 887
AdamNYC Avatar asked Mar 03 '12 22:03

AdamNYC


People also ask

How do I copy a branch name?

Hold ctrl and left click with the mouse on the branch name. This will prompt a context menu, click Copy. The fast way is to ctrl + double left click so you instantly close the context menu and select the branch name.

What is branch command in git?

The git branch command lets you create, list, rename, and delete branches. It doesn't let you switch between branches or put a forked history back together again. For this reason, git branch is tightly integrated with the git checkout and git merge commands.


2 Answers

If you're on a Unix-like system (Linux, Mac OS X, perhaps others), there's the contrib/complete/git-completion.bash bash auto-complete ruleset, which will let you auto-complete git commands (you can type git checkout step110<tab> and your shell will autocomplete the branch-name.

To activate this:

  • If you've got the git source, in contrib/complete/ there's a file git-completion.bash. Put that somewhere safe (like ~/.git-completion), and then add the following line to your ~/.bashrc file: source ~/.git-completion. Either restart your shell session or run source ~/.git-completion to get it running in the current shell session.
  • If you dont have the git source, you can get the script from here (github.com). Then follow the same instructions as above.

If you're lucky enough to be using zsh instead of bash, I know that oh-my-zsh has git autocompletion plugins (I'm not sure how to activate them without oh-my-zsh).

Sources:

  • mbuttu.wordpress.com
  • codethatmatters.com
like image 184
simont Avatar answered Sep 19 '22 12:09

simont


Here is how I installed it on OS X...

Check if it's on your local system first. It seems MacPorts and Homebrew download it for you.

$ find / -name "git-completion.bash" 

Otherwise, download it...

$ wget https://raw.github.com/git/git/master/contrib/completion/git-completion.bash -O ~/.git-completion 

If you don't have wget, you can install it easily with Homebrew or use cURL.

$ vim ~/.profile 

...or your editor of choice.

Then add...

source ~/.git-completion 

If your autocompletion doesn't work automatically...

$ source ~/.profile 

...and then you have Git autocompletion.

like image 44
alex Avatar answered Sep 20 '22 12:09

alex