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
- How to add a Blank Directory to your Git Repository
- Git: Renaming a Branch
- How to move your Githooks to your Repo
- Resolving Git Merge Conflicts
- Setting upstream with Git
- Git blame - How to find out who modified a line with Git
- How to make Git ignore file permission (chmod) changes
- How to Auto Compress Your CSS and JS with Git Hooks
- How to amend and update a git commit
- Git Merge: Merging Changes from other Branches