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/..
).
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/..
).
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 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.
upstream
is generally: stackoverflow.com/questions/2739376/… –
Wurst git remote -v
, if only upstream was specified, in my case, unless your referring to other times, maybe when pushing? That is probably what i was asking, how does that impact pushing/pulling if i only have upstream, and no origin? Or could that instead be a correct(alternative) way to imply origin, by not specifying, just specify upstream?? Or, is it anti-pattern use, in favor of just double specifying, or should i just add origin and leave upstream empty for prod? –
Yuriyuria git fetch
will get from upstream
and git pull
from origin
? –
Calamite origin
). But at any time, you can chose to fetch from upstream: git fetch upstream
. –
Wurst upstream
mean anything specific or is it simply a conventional name used when working with forks in git, e.g. could you use any name instead of it? –
Roose upstream
that branch. Just work-locally -> git-add -> git-commit -> git-push, right? –
Kellum master
branch is automatically linked to remote tracking branch origin/master
because of the clone from origin after the fork. But wouldn't it make more sense that the local master
branch track upstream/master
since one would often do a fetch to sync the two? I don't think there would often be a need to keep local master
in sync with updates from origin/master
. Plus then the command git branch -vv
would show how many commits the local master
is behind from upstream/commit
. –
Kan git
has no idea that what it is cloning is a fork ("fork" is a GitHub feature). As such, it only set the upstream branch of main
to origin/main
, without knowing there could be an upstream original repository worth referencing. –
Wurst git://github.com/<aUser>/<aRepo.git>
should be changed to https://github.com/<aUser>/<aRepo.git>
? At least the former did not work for me but the latter did. –
Serration git://
is no longer supported. I have edited the answer accordingly, with a link illustrating why git://
is no longer there. –
Wurst In a nutshell answer.
In the context of GitHub, "origin" and "upstream" refer to two different repositories.
"Origin" typically refers to your own fork of a repository. When you fork a repository on GitHub, you create a copy of it in your own account. This copy is called a fork, and the original repository is called the upstream repository. When you clone your fork to your local machine, Git automatically sets up a remote called "origin" that points to your fork on GitHub.
"Upstream" refers to the original repository that you forked from. This is the repository that you originally copied when you created your fork. You can set up a remote called "upstream" that points to this repository, which allows you to keep your fork up to date with any changes that are made to the upstream repository.
"origin" refers to your own fork of a repository, while "upstream" refers to the original repository that you forked from.
Let's say you want to contribute to an open-source project on GitHub called "example-project" that is owned by another user. To contribute to this project, you would typically fork the repository to your own account, clone it to your local machine, make changes, and then submit a pull request to the original repository.
Here's how the "origin" and "upstream" repositories come into play:
Fork the repository: You go to the "example-project" repository on GitHub and click the "Fork" button. This creates a copy of the repository in your own account, which is now called "your-username/example-project".
Clone the repository: You clone your fork of the repository to your local machine using the git clone command. This sets up a local copy of the repository on your machine.
Set up "origin" remote: When you clone your fork, Git automatically sets up a remote called "origin" that points to your fork on GitHub. This allows you to push changes to your fork using the git push command.
Set up "upstream" remote: To keep your fork up to date with any changes that are made to the original repository, you can set up a remote called "upstream" that points to the original repository. You can do this using the git remote add command. For example:
git remote add upstream https://github.com/original-user/example-project.git
This sets up a remote called "upstream" that points to the original repository.
Fetch changes from "upstream": To get any changes that have been made to the original repository, you can run the git fetch command with the "upstream" remote. For example:
git fetch upstream
This fetches any changes that have been made to the original repository.
Merge changes into your fork: Once you've fetched changes from the original repository, you can merge them into your fork using the git merge command. For example:
git merge upstream/main
This merges any changes that have been made to the "main" branch of the original repository into your local copy of the repository.
Push changes to "origin": Once you've made changes to your local copy of the repository, you can push them to your fork on GitHub using the git push
command. For example:
git push origin main
This pushes any changes that you've made to the "main" branch of your fork to your fork on GitHub.
In summary, "origin" refers to your own fork of the repository, while "upstream" refers to the original repository that you forked from. By setting up "upstream" as a remote, you can keep your fork up to date with any changes that are made to the original repository.
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.
fatal: The current branch branchName has no upstream branch. push the current branch and set the remote as upstream,
like - git push --set-upstream origin branchName
. There is nothing related to fork here, so what is upstream
here? Anyone can help? –
Hanseatic © 2022 - 2024 — McMap. All rights reserved.