1

Normally when I run git status on a master branch that has a corresponding remote I get info that gives me a comparison between my current branches state and its remote (at the last point communication occurred), e.g. something like

your branch is X commits ahead of 'origin/master'

or

Your branch is up-to-date with 'origin/master'

In a git repository I created a new branch

git checkout -b new_branch
  • added some new commits
  • and pushed to to remote

Now if I add any new commits to my local repository on the new_branch and run git status it doesnt give me any information about how my local branch compares to its remote.
How can I get git to report this information automatically, like it does on master?

the_velour_fog
  • 1,914
  • 3
  • 13
  • 22

2 Answers2

3

Your branch is not yet tracking an upstream branch. See tracking branches. To resolve it, set the upstream branch once when you push.

git push --set-upstream origin new_branch
Jeremy Fortune
  • 2,169
  • 1
  • 14
  • 16
  • Am I correct in assuming this would only work at the time I created the branch? as the branch exists Im wondering if I should use git branch -u origin new_branch` as per the linked answer – the_velour_fog Jun 27 '15 at 13:13
  • No, you can do it at any time. The only real difference is that `push` will push refs, while `branch -u` just sets the attribute. Both work. – Jeremy Fortune Jun 27 '15 at 17:26
2

You can do the following:

git branch -u origin/branch_name

This will set up the branch branch_name to track remote branch branch_name from origin.

As per git-scm.com:

If you already have a local branch and want to set it to a remote branch you just pulled down, or want to change the upstream branch you’re tracking, you can use the -u or --set-upstream-to option to git branch to explicitly set it at any time.

Rahul Gupta
  • 39,529
  • 10
  • 89
  • 105