1

Is there a way to refer to the current branch during git push origin instead of using full name like:

git push origin myBranch

I was thinking of linux "." like operator to refer to current branch without having to use its full name.

Ace
  • 1,501
  • 4
  • 30
  • 49
  • 2
    If your local branch is tracking a remote one, then you can do just `git push` – Sergio Tulentsev Mar 13 '17 at 14:55
  • 1
    When pushing, I think you can just do `git push`. Edit: Oops, barely ninja'd. – AAM111 Mar 13 '17 at 14:55
  • Possible duplicate of [How to get the current branch name in Git?](http://stackoverflow.com/questions/6245570/how-to-get-the-current-branch-name-in-git) – AAM111 Mar 13 '17 at 14:56
  • If you do git status and you see something like (Your branch is up-to-date with 'origin/myBranch'), then all you need to do is git push – justMe Mar 13 '17 at 14:57

1 Answers1

2

Do this:

git branch --set-upstream-to origin/myBranch

Then you can just do

git push

From the man page:

--set-upstream-to=<upstream> Set up <branchname>'s tracking information so <upstream> is considered <branchname>'s upstream branch. If no <branchname> is specified, then it defaults to the current branch.

See this other answer for details

Community
  • 1
  • 1
smac89
  • 39,374
  • 15
  • 132
  • 179
  • Thanks, could you please explain what --set-upstream-to does? – Ace Mar 13 '17 at 14:57
  • 2
    @GoldenSugar: JFYI, you can `git branch --help` – Sergio Tulentsev Mar 13 '17 at 14:58
  • It's `--set-upstream`, not `--set-upstream-to`. At least in git 2.11.0 – Sergio Tulentsev Mar 13 '17 at 14:59
  • @SergioTulentsev, using git 2.12.0, the option is `set-upstream-to`. What version of git do you have? – smac89 Mar 13 '17 at 15:00
  • @SergioTulentsev, didn't refresh :p – smac89 Mar 13 '17 at 15:04
  • Note that the user must have Git version 2.0 or above and/or have configured `push.default` to `simple` *and* not have other special situations going on. (The situation is a bit complicated: 2.0-or-later *defaults* to a `push.default` of `simple`, but Git 1.9 defaults to `matching`; and there are ways to override all these settings.) – torek Mar 13 '17 at 18:15
  • @SergioTulentsev: `--set-upstream` is the old option, `--set-upstream-to` is the new preferred option (new in Git 1.8.0). The key difference between them is the way the upstream-to-set and the branch-whose-upstream-is-to-be-set are specified: people were always getting it backwards in Git 1.7.x. – torek Mar 13 '17 at 18:17