REMOTE-NAME is the name of your remote repository. For example: origin. BRANCH-NAME is the name of your branch.
To view your remote branches, simply pass the -r flag to the git branch command. You can inspect remote branches with the usual git checkout and git log commands. If you approve the changes a remote branch contains, you can merge it into a local branch with a normal git merge .
Git checkout remote branch is a way for a programmer to access the work of a colleague or collaborator for the purpose of review and collaboration. There is no actual command called “git checkout remote branch.” It's just a way of referring to the action of checking out a remote branch.
You can do it more simply, guaranteeing that your .gitconfig
is left in a meaningful state:
git push -u hub master
when pushing, or:git branch -u hub/master
(This will set the remote for the currently checked-out branch to hub/master
)git branch --set-upstream-to hub/master
(This will set the remote for the branch named branch_name
to hub/master
)git branch branch_name --set-upstream-to hub/master
v1.7.x
or earlieryou must use --set-upstream
:git branch --set-upstream master hub/master
Track the remote branch
You can specify the default remote repository for pushing and pulling using git-branch’s track option. You’d normally do this by specifying the --track option when creating your local master branch, but as it already exists we’ll just update the config manually like so:
Edit your .git/config
[branch "master"]
remote = origin
merge = refs/heads/master
Now you can simply git push and git pull.
[source]
For the sake of completeness: the previous answers tell how to set the upstream branch, but not how to see it.
There are a few ways to do this:
git branch -vv
shows that info for all branches. (formatted in blue in most terminals)
cat .git/config
shows this also.
For reference:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With