the_velour_fog
the_velour_fog

Reputation: 2184

How do I get a new git branch to show its state relative to its remote?

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

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?

Upvotes: 1

Views: 94

Answers (2)

Rahul Gupta
Rahul Gupta

Reputation: 47866

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.

Upvotes: 2

Jeremy Fortune
Jeremy Fortune

Reputation: 2499

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

Upvotes: 3

Related Questions