What is the difference between origin
and upstream
on GitHub?
When a git branch -a
command is executed, some branches it displays have a prefix of origin
(remotes/origin/..
) while others have a prefix of upstream
(remotes/upstream/..
).
upstream generally refers to the original repo that we have forked. origin is our fork: our own repo on GitHub, clone of the original repo of GitHub.
In Git, "origin" is a shorthand name for the remote repository that a project was originally cloned from. More precisely, it is used instead of that original repository's URL - and thereby makes referencing much easier.
A remote is just a word: a name to use to identify some other Git repository somewhere. The string origin is the default name of the (singular) remote that git clone puts in automatically, when you clone from some other ("origin"-al) Git repository. You can choose some other name, and/or add more remotes.
In order to switch to the local “dev” branch, and to set the “origin/dev” as the tracking branch (or upstream branch), use the “–track” option. To verify that you linked dev to the tracking branch “origin/dev” (which upstream branch is the remote dev), use the “git branch” command.
This should be understood in the context of GitHub forks (where you fork a GitHub repo on GitHub before cloning that fork locally).
upstream
generally refers to the original repo that you have forkeddownstream
” and “upstream
”" for more on upstream
term) origin
is your fork: your own repo on GitHub, clone of the original repo of GitHubFrom the GitHub page:
When a repo is cloned, it has a default remote called
origin
that points to your fork on GitHub, not the original repo it was forked from.
To keep track of the original repo, you need to add another remote namedupstream
git remote add upstream git://github.com/<aUser>/<aRepo.git>
(with aUser/aRepo
the reference for the original creator and repository, that you have forked)
You will use upstream
to fetch from the original repo (in order to keep your local copy in sync with the project you want to contribute to).
git fetch upstream
(git fetch
alone would fetch from origin
by default, which is not what is needed here)
You will use origin
to pull and push since you can contribute to your own repository.
git pull git push
(again, without parameters, 'origin' is used by default)
You will contribute back to the upstream
repo by making a pull request.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With