Article reference: HTTP://WWW.JIANSHU.COM/P/9FD449340EA5
First confirm the noun:
Main Warehouse: Everyone uses
Fork Library: Fork The main warehouse, you use it alone.
Local library: Local working library
1. Workaround 1
First, determine if you have established a remote source for the main repo: Git remote-v
If you can only see your own two sources (fetch and push), then you need to add the source of the main repo: Git remote add upstream URL
Git remote-v
The upstream here is a local alias for the remote branch we established. Note: There is usually https or SSH, if it is the way ssh, you need to add SSH URL, can not add https, otherwise you can not access the URL under SSH, in addition, if you want to delete remote upstream tag, you can run: git Remote RM Upstream
Then you can see the upstream.
If you want to merge with the main repo: git fetch upstream
git merge Upstream/master
The above is based on the case where you do not fork the other library.
If you fork a library, you can update your fork library from the main repository first. (if it's a community mode, just launch a pull request and it's OK)
The code for the Fork library is then downloaded locally.
2. Workaround 2
Fork is the remote side of a copy of someone else's warehouse.
When you fork a warehouse on a remote side (such as Github), your remote repository creates a new "warehouse copy" of the fork. If you want to modify this copy repository locally, you need to clone it locally:
git clone git@github.com:your_username/your_fork# or git clone git@github.com:your_username/your_fork# or git clone https ://github.com/your_username/your_fork
Now that you have a local copy of the fork, you can start modifying the code locally.
Synchronizing updates
Process: Main warehouse-①fetch & merge–>
Local Warehouse-②push–>
Fork Library
So far, the remote information for your local repository can be used by Git remote-v
Check to see:
Https://github.com/YOUR_USERNAME/YOUR_FORK.git (FETCH) https://github.com/YOUR_USERNAME/YOUR_FORK.git (push)
In order to get an update to the fork source Warehouse, now add the address of the fork source warehouse, for example:
$ git remote add upstream https://github.com/ORIGINAL_OWNER/ORIGINAL_REPO.git
Here's upstream
is a name that can be modified to represent the alias of the fork source warehouse.
With $ git remote-v
View the remote address associated with the local warehouse to:
Origin Https://github.com/YOUR_USERNAME/YOUR_FORK.git (Fetch) Origin https://github.com/YOUR_USERNAME/YOUR_ Fork.git (push) upstream https://github.com/ORIGINAL_OWNER/ORIGINAL_REPO.git (fetch) upstream https://github.com/ Original_owner/original_repo.git (push)
The above set up, when you want to update fork source warehouse, first fetch a copy of the source warehouse changes to local, this back to create a branch Upstream/master
:
$ git fetch upstream
You can view all branches with the View Branch command:
$ git Branch
Then, switch to the local master branch:
$ git Checkout Master
Merging Upstream/master
Branch changes to the local master branch:
$ git Merge Upstream/master
Here, only the main repository is updated to the local repository, and if you want to update the Fork warehouse vice at the remote end, you must push it to the remote end:
$ GIT push origin master
Above, fork source warehouse, fork warehouse copy and local warehouse are updated synchronously.