6

I would like to do something like this:

$ git fetch origin
$ git rebase -i origin/a_very_very_very_long_branch_name

Where, my local branch name is as same as a_very_very_very_long_branch_name.

So when I execute this kind of command, I don't want to copy and paste the long branch name again and again.

Are there any shortcuts for the current branch name in Git?

try-catch-finally
  • 7,436
  • 6
  • 46
  • 67
Ya Zhuang
  • 4,652
  • 31
  • 40
  • If you tab out, it should autocomplete your branch name. – wakooka May 04 '13 at 05:22
  • @jerome.s yeah, but i have, or, let's say, the project have too many branches( i know it's not good, but C'est La Vie ;( ). so i'm still finding the "shortcuts" – Ya Zhuang May 04 '13 at 05:26
  • you might want to try out git-completion https://github.com/git/git/blob/master/contrib/completion/git-completion.bash – Sébastien Dawans May 04 '13 at 05:28
  • @SébastienDawans http://stackoverflow.com/questions/16370845/is-there-any-shortcuts-for-current-git-branch?noredirect=1#comment23459292_16370845 – Ya Zhuang May 04 '13 at 05:36
  • 1
    I think you're looking for `HEAD`. See http://stackoverflow.com/questions/2304087/what-is-git-head-exactly/2304106 – Kyle Strand May 04 '13 at 05:53
  • @jerome.s since I launch the the `sh.exe --login -i` (windows), in *emacs* therefore tab out isn't an option that can be taken for granted – Bleeding Fingers May 04 '13 at 06:05

3 Answers3

4

If your branch is set up to track the remote branch of the same name in origin, you can use @{u} as pointed out in the manpage gitrevisions:

<branchname>@{upstream}, e.g. master@{upstream}, @{u}

The suffix @{upstream} to a branchname (short form <branchname>@{u}) refers to the branch that the branch specified by branchname is set to build on top of. A missing branchname defaults to the current one.

Community
  • 1
  • 1
Nevik Rehnel
  • 49,633
  • 6
  • 60
  • 50
4

In your particular example, if your branch is tracking the remote branch, you can just do

git fetch
git rebase -i

Without parameters.

In case your branch is not tracking the remote branch, that can be set up by doing

git branch -u origin/a_very_very_very_long_branch_name
Klas Mellbourn
  • 42,571
  • 24
  • 140
  • 158
  • Though it's usable in the provided _example_ it is not exactly what was asked for: "shortcut for current branch name". (I aware that the TO had a X/Y problem because she/he actually wanted to know the upstream/remote branch name. But I'll ignore that since the text is clear and the question is old.) – try-catch-finally Jul 28 '17 at 15:49
2

You could always create an alias to do the rebase to origin/current-branch;

git fetch ; git rebase -i origin/$(git rev-parse --abbrev-ref HEAD)

Or, if you don't specifically need the interactive part of the rebase;

git pull --rebase

Jakob Borg
  • 23,685
  • 6
  • 47
  • 47