How to sync your GitHub repository after fork from others '.

Source: Internet
Author: User
ArticleDirectory
    • The setup
    • Syncing
Syncing A forkthe setup

Before you can sync, you need to add a remote that points to the upstream Repo. You may have done this when you originally forked.

  git remote-v  # list the current remotes   # origin https://github.com/ User / repo . git (FETCH)   # origin https://github.com/ User / repo . git (push)   git remote add upstream https://github.com/ otheruser / repo . git  # set a new remote   git remote-v  # verify new remote    # origin https://github.com/ User / repo . git (FETCH)   # origin https://github.com/ User / repo . git (push)   # upstream https://github.com/ otheruser / repo . git (FETCH)   # upstream https://github.com/ otheruser / repo . git (push)  
Syncing

There are two steps required to sync your repo with the upstream: First you must fetch from the remote, then you must merge the desired branch into your local branch.

Fetching

Fetching from the remote repo will bring in its branches and their respective commits. These are stored in your local repo unders special branches.

Git fetch upstream# Grab the upstream remote's branches#Remote: counting objects: 75, done.#Remote: compressing objects: 100% (53/53), done.#Remote: Total 62 (delta 27), reused 44 (Delta 9)#Unpacking objects: 100% (62/62), done.#From https://github.com/Otheruser/Repo#* [New branch] Master-> upstream/Master

We now have the upstream's master branch stored in a local branch,Upstream/Master

Git branch-va# List all local and remote-tracking branches#* Master a422352 my local commit#Remotes/ORIGIN/head-> origin/Master#Remotes/ORIGIN/Master a422352 my local commit#Remotes/upstream/Master 5fdff0f some upstream commit
Merging

Now that we have fetched the upstream Repo, we want to merge its changes into our local branch. This will bring that branch into sync with the upstream, without losing our local changes.

Git checkout master# Check out our local master Branch#Switched to branch 'master'Git merge upstream/Master# Merge upstream's master into our own#Updating a422352.. 5fdff0f#Fast-forward#Readme | 9 -------#Readme. md | 7 ++#2 files changed, 7 insertions (+), 9 deletions (-)#Delete mode 100644 readme#Create mode 100644 readme. md

If your local branch didn't have any unique commits, git will instead perform a "fast-forward ":

$ Git merge upstream/Master#Updating 34e91da... 16c56ad#Fast-forward#Readme. md | 5 ++ --#1 file changed, 3 insertions (+), 2 deletions (-)

 

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.