Fork someone else's project on GitHub and save the Sync method

Source: Internet
Author: User
Tags ssh git clone

First determine if you have established a remote source for the main repo:

Git remote-v

If you only see your own two sources (fetch and push)

Origin  Git@github.com:pudoj/thingsboard.git (fetch)
origin  Git@github.com:pudoj/thingsboard.git ( Push

Then you need to add the source of the main repo:

git remote add thingsboard https://github.com/thingsboard/thingsboard.git
git remote-v
Origin  Git@github.com:pudoj/thingsboard.git (Fetch)
origin  Git@github.com:pudoj/thingsboard.git (push)
Thingsboard https://github.com/thingsboard/thingsboard.git (Fetch)
Thingsboard https://github.com/ Thingsboard/thingsboard.git (push)

The Thingsboard 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 the SSH URL, can not add the way of HTTPS, otherwise you can not access the URL under SSH, in addition, If you want to delete the remote Thingsboard tag, you can run:

Git remote RM thingsboard

Then you can see the Thingsboard.

If you want to merge with the main repo:

git fetch thingsboard
git merge Thingsboard/master

* * The above steps are already able to fork others in the project synchronized update;
But the actual situation is often fork other's project, you will also modify the project, of course, the original author will also modify his own project, at this time the synchronization method is as follows: *

process : Fork source warehouse-①fork–> Fork Warehouse copy-②clone–> local 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# 
$ 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: Fork Source Warehouse-①fetch & merge–> Local warehouse-②push–> Fork Warehouse Copy

So far, the remote information for your local warehouse can be used

$ 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

The Thingsboard here is a name that can be modified to represent the alias of the fork source warehouse.
Use

$ 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)
Thingsboard https://github.com/ORIGINAL_OWNER/ORIGINAL_REPO.git (fetch)
Thingsboard 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 Thingsboard/master

$ git fetch thingsboard

You can view all branches with the View Branch command:

$ git Branch

Then, switch to the local master branch:

$ git Checkout Master

Merging Thingsboard/master
Branch changes to the local master branch:

$ git Merge Thingsboard/master

Here, only the fork source warehouse is updated to the local warehouse, and if you want to update the fork warehouse copy on the remote side, 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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.