Git

Setting upstream with Git

📣 Sponsor

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:

# 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

git remote -v

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

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.

# 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

# remote is your remote, usually origin # branch is the branch you are on, usually master git push --set-upstream [[remote]] [branch]
Last Updated 1609430974026

More Tips and Tricks for Git

Subscribe for Weekly Dev Tips

Subscribe to our weekly newsletter, to stay up to date with our latest web development and software engineering posts via email. You can opt out at any time.

Not a valid email