Update Git Fork From Base Repository

Git is a distributed version control system, developed by Linus Torvalds in 2005 and currently maintained by Junio C Hamano. There are many popular GUI tools and extensions available to use git but originally git was developed as a command-line tool. It is still fun to use git using the command line. You will also understand under the hood magic performed by GUI tools.
 

What is Fork?

 
A fork is a copy of a repository in your GitHub account. Forking a repository allows you to freely experiment with changes without affecting the original project.
 
Forks act as a sort of bridge between the original repository and your personal copy.
 
Most commonly, forks are used to either propose changes to someone else's project or to use someone else's project as a starting point for your own idea.
 

Propose changes to someone else's project

 
For example, you can use forks to propose changes related to fixing a bug. Rather than logging an issue for a bug you've found, you can:
  • Fork the repository
  • Make the fix.
  • Submit a pull request to the project owner.
Open-source software is based on the idea that by sharing code, we can make better, more reliable software. For more information, see the “About the Open Source Initiative" on the Open Source Initiative.
 
For some more information on how to fork a repository, check out our guide, "Forking Projects"
 

Update Local Fork Repository

 
Before updating your fork, make sure there are no changes pending for pushing to the base repository.
 
If pending then you should create a pull request before upstreaming fork. 
 
First, verify that you have already set up a remote for theupstream repository, and hopefully an origin too.
 
Here I’m upgrading nopCommerce’s document repository which I’ve forked.
  1. git remote -v  
  2. origin https://github.com/rajupaladiya/nopCommerce-Docs.git (fetch)  
  3. origin https://github.com/rajupaladiya/nopCommerce-Docs.git (push)  
git remote -v
 
Here you don’t have upstream.
 
So you need to specify a remote upstreamrepo to sync with your fork,
 
git remote add upstream https://github.com/nopSolutions/nopCommerce-Docs.git
 
git remote add upstream https://github.com/nopSolutions/nopCommerce-Docs.git
 
Verify that the remote is added correctly,
 
git remote -v
 
Update Git Fork From Base Repository
 
Now you can collect the latest changes in the upstream repository with fetch. Repeat this every time you want to get updates,
 
(If the project has tags that have not merged to master you should also do: git fetch upstream --tags)
 
git merge upstream/master
 
Update Git Fork From Base Repository
 
Fetch branches and commits from the upstream repo. You’ll be storing the commits to master in a local branch upstream/master,
 
git checkout master
 
Update Git Fork From Base Repository
 
Fetch branches and commits from the upstream repo. You’ll be storing the commits to master in a local branch upstream/master:
 
git merge upstream/master
 
Update Git Fork From Base Repository
 
Push changes to update your fork on Github.
 
That's all, now your fork repository is up to date.
 
Here are all command-lines in sequence
  1. git remote -v      
  2. git remote add upstream https://github.com/nopSolutions/nopCommerce-Docs.git      
  3. git remote -v      
  4. git fetch upstream      
  5. git checkout master      
  6. git merge upstream/master   


Similar Articles