jan
jan

Reputation: 6171

What is the difference between origin and upstream on GitHub?

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/..).

Upvotes: 580

Views: 245882

Answers (4)

JustAG33K
JustAG33K

Reputation: 1566

Upstream

Upstream generally refers to the original repo that you have forked. To keep track of the original repo, you need to add another remote named upstream.

When we run this command:

git push -u origin master

The -u flag means that your local branch will become a tracking branch. That is, a branch that tracks a remote branch (the upstream branch), so that future git pull will know which branch to merge from and git push will be directed to the correct remote branch.

Origin

When you clone a repository with git clone command, it automatically creates a remote connection called origin pointing back to the cloned repository. Origin is your fork of your own repo on GitHub, clone of the original repo of GitHub.

By running this command:

git push origin branchname

Upvotes: 13

VonC
VonC

Reputation: 1328342

This should be understood in the context of GitHub forks (where you fork a GitHub repo on GitHub before cloning that fork locally).

From 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 named upstream

git remote add upstream https://github.com/<aUser>/<aRepo.git>

(with aUser/aRepo the reference for the original creator and repository, that you have forked)

Note: since Sept. 2021, the unauthenticated git protocol (git://...) on port 9418 is no longer supported on GitHub.

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.

fork and upstream

Upvotes: 1093

TUSqasi
TUSqasi

Reputation: 836

In a nutshell answer.

  • origin: the fork
  • upstream: the forked

Upvotes: 64

Jude Ukana
Jude Ukana

Reputation: 119

after cloning a fork you have to explicitly add a remote upstream, with git add remote "the original repo you forked from". This becomes your upstream, you mostly fetch and merge from your upstream. Any other business such as pushing from your local to upstream should be done using pull request.

Upvotes: 3

Related Questions