Git

Setting upstream with Git

Setting the upstream location for git means that you can simply type git fetch or git push and have the server automatically fetch or push to that upstream location.

Imagine a situation where you clone a git repository using git clone, and you want to add an upstream so you can both pull and push from that remote git repository. The easiest way to do this is by using git push like this:

shell Copy
# remote is your remote, usually origin # branch is the branch you are on, usually master # -u means to save the settings for future git push -u [remote] [branch]

If your remote is not called origin, you can find a list of your remote's name by running the following

shell Copy
git remote -v

Which will usually return something like this, where 'origin' below is the name of the remote repo:

shell Copy
origin git@github.com:user/repo.git (fetch) origin git@github.com:user/repo.git (push)
If you have no remote repos set up, you can set one up by doing the following, and then doing git push -u [remote] [branch] to set the default upstream location.

shell Copy
# replace git@github.com:user/repo.git with your repo. git remote add git@github.com:user/repo.git

If git push -u <remote><branch> isn't working for you, you can also set the upstream by doing this

shell Copy
# remote is your remote, usually origin # branch is the branch you are on, usually master git push --set-upstream [[remote]] [branch]
Last Updated Thursday, 31 December 2020