αƞjiβ
αƞjiβ

Reputation: 3246

How to find whether my local branch is tracking remote branch or not?

Long time ago I clone the project from remote server.Recently I mostly worked on one particular branch of this project. Now I need to push the changes to this branch only (not to master).

I think I can do this with command

git push origin localBranchName:remoteBranchName

Also I can add -u to track this remote branch. But i might be tracking already so my question is how can I make sure I am tracking remote branch from this local branch. Is there git command or option that I can use?

Upvotes: 0

Views: 126

Answers (3)

Max Komarychev
Max Komarychev

Reputation: 2856

Just use git status (reference: http://git-scm.com/docs/git-status)

git status will show desired information for the branch you currenly on.

Example output:

$ git status
On branch master
Your branch is up-to-date with 'origin/master'.

nothing to commit, working directory clean

In this example local branch master tracks branch master on remote origin

You may also find useful shorter version: git status -sb which will output:

## master...origin/master if you branch tracks the remote

## master if it is not.

Upvotes: 3

Chris Cleeland
Chris Cleeland

Reputation: 4900

As noted in another answer, git branch offers a way to print out the upstream branch for a local branch. That information is also stored in .git/config in the section for the branch. For example, for branch "myniftybranch" tracking upstream "origin/foo", you will find a section in .git/config that looks like this:

[branch "myniftybranch"]
remote = origin
merge = refs/heads/foo

Hope that helps.

Upvotes: 1

rmorrin
rmorrin

Reputation: 2485

You could use the -vv (very verbose) flag of git branch:

$ git branch -vv

Which will list all local branches, along with their default tracking branch.

Upvotes: 4

Related Questions