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]
More Tips and Tricks for Git
- The Complete Beginners Guide to Getting Started with Git
- Git: Renaming a Branch
- How to undo a git pull
- Setting upstream with Git
- How to amend and update a git commit
- How to Auto Compress Your CSS and JS with Git Hooks
- A Step by Step Guide to Git Branches
- How to make Git ignore file permission (chmod) changes
- Git Stash - Everything about stashing changes in git
- How to make Git forget a tracked file now in .gitignore