Git Set Remote Upstream URL

preview_player
Показать описание


In Git, the upstream branch typically refers to the original repository from which a fork was created. When you fork a repository on GitHub, you essentially create a copy of that repository under your own GitHub account. The original repository becomes the upstream repository for your fork.

Here's how it typically works:

1. Forking: You find a repository on GitHub that you want to contribute to or work with. You fork this repository, creating a copy under your own GitHub account.

2. Cloning: After forking, you clone your forked repository to your local machine using Git. At this point, your forked repository's `origin` points to your forked repository on GitHub.

3. Setting Upstream: To keep track of changes happening in the original repository (the one you forked from), you add a remote called `upstream` that points to the original repository. This is typically done using the `git remote add` command. This remote is named `upstream` by convention, but you can name it differently if you prefer.


git remote add upstream original_repository_url


4. Fetching Changes: Periodically, you fetch changes from the upstream repository to your local repository. This ensures that you have the latest updates from the original repository.


git fetch upstream


5. Updating Fork: Once you have fetched changes from the upstream repository, you can merge or rebase those changes into your local branch and then push them to your fork on GitHub.


git checkout branch_name
git merge upstream/branch_name


or


git rebase upstream/branch_name


and then


git push origin branch_name


By keeping track of changes in the upstream repository, you can ensure that your fork remains up-to-date with any changes made in the original repository. This is especially important if you're contributing to an open-source project where the original repository might be actively maintained and updated by other contributors.
Рекомендации по теме