Skip to content

Instantly share code, notes, and snippets.

@hackjutsu
Last active June 17, 2025 13:33
Show Gist options
  • Select an option

  • Save hackjutsu/33b970dd117889485491c018543e5118 to your computer and use it in GitHub Desktop.

Select an option

Save hackjutsu/33b970dd117889485491c018543e5118 to your computer and use it in GitHub Desktop.
[set upstream] What does '--set-upstream' do? #tags: git
git branch --set-upstream-to <remote-branch>
# example
git branch --set-upstream-to origin feature-branch

# show up which remote branch a local branch is tracking
git branch -vv

sets the default remote branch for the current local branch.

Any future git pull command (with the current local branch checked-out), will attempt to bring in commits from the <remote-branch> into the current local branch.

One way to avoid having to explicitly do --set-upstream is to use the shorthand flag -u along with the very first git push as follows

git push -u origin local-branch

@yeikarina

Copy link
Copy Markdown

it was helpful! thankyou! :)

@prabhakargitact

Copy link
Copy Markdown

Thank you!

@john-raymon

Copy link
Copy Markdown

Thanks!

@eddyboundera

Copy link
Copy Markdown

So helpful. thanks

@zaxo7

zaxo7 commented Nov 6, 2019

Copy link
Copy Markdown

Thanks ;D

@Betlista

Copy link
Copy Markdown

Second link on Google for "what is git upstream branch". Simple and easy.

First result was https://git-scm.com/book/en/v2/Git-Branching-Remote-Branches, scary...

Thanks!

@dm0yang

dm0yang commented Feb 21, 2020

Copy link
Copy Markdown

Thanks! The very last line can be misleading:

git push -u origin local-branch

Did you actually mean:

git push -u origin remote-branch

:)

@knightelessar

Copy link
Copy Markdown

This is gold!
This could potentially help more people if you consider updating this into the git push documentation. Currently, the following is not as easy-to-understand as yours:

For every branch that is up to date or successfully pushed, add upstream (tracking) reference, used by argument-less git-pull[1] and other commands. For more information, see branch..merge in git-config[1].

@wgova

wgova commented Mar 24, 2020

Copy link
Copy Markdown

Thanks! The very last line can be misleading:

git push -u origin local-branch

Did you actually mean:

git push -u origin remote-branch

:)

No. local-branch because you are currently on a remote branch

@MDAX1

MDAX1 commented Apr 25, 2020

Copy link
Copy Markdown

very helpful thank you! 👍

@life-efficient

Copy link
Copy Markdown

🔥

@azibom

azibom commented May 19, 2020

Copy link
Copy Markdown

Your explanation is very clear and helpful, Thanks

@theAkito

Copy link
Copy Markdown

Best solution for this situation, because it does not require you to git push.

@Divsdev

Divsdev commented Aug 26, 2020

Copy link
Copy Markdown

You made our life easier. First time creating branch in a prod project. Thanks man!

@ywroh

ywroh commented Aug 31, 2020

Copy link
Copy Markdown

thank u for good info.

@dougouverson

Copy link
Copy Markdown

Thank you!

@lone-wolve

Copy link
Copy Markdown

Thank you it was helpful

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment