DEV Community

Cover image for Keeping a forked git repository updated using git cli
Ukpai Chukwuemeka
Ukpai Chukwuemeka

Posted on • Originally published at Medium

Keeping a forked git repository updated using git cli

As an intermediate using git i experienced similar issues you might be experiencing now not knowing how to get latest changes from a git repository.
Work with different teams at the hng internship i really couldn’t keep count of how many PR(pull Request) i had to close because of conflicts i had when making a pull request. So i just thought of putting out something that could be of help to you.
Why is keeping your repository synced important?
When working with a team different people make contributions either on a daily basis depending on the team.So it important you get latest changes before you push or even make a PR if that isn’t done there is no Escape Route for conflicts when making a PR.

get your PC ready !!!.
STEP 1:

  • Fork the Git repository

STEP 2 :

  • create a new folder on your PC
  • Right click on the created folder and do a git bash here or if you have a text editor like VScode,open up the folder in your text editor and use the terminal.

STEP 3:

  • copy the repository URL
  • on your terminal do a git clone <repository URL>

STEP 4:

  • checkout to a new branch git checkout -b <branch name> N🅱️ This branch is where you would be making your changes to before you push.

Creating Upstream
STEP 5:

  • git remote add upstream <https://github.com/original_owner/original_repository.git> N🅱️ get the URL from the original repository STEP 6: To get latest updates from any of the branch
  • do a git checkout <branch name>
  • git pull upstream <branch name> N🅱️ branch name here is the branch name of on the original repository you want to pull changes from.

STEP 7:

  • git checkout <branch name> N🅱️ checkout to the branch you are working on

STEP 8:

  • then git merge <branch name> N🅱️branch name here is the branch you pulled to,Also if you are using a text editor like VScode if there are any conflict you would get notified.

AT LAST:

STEP 9:

  • git push -u origin HEAD N🅱️ using HEAD you dont have to type the branch.it pushes directly to the branch you are one.

CONGRATULATION YOU JUST AVOIDED CONFLICTS….
Kindly hit the like button and follow if you found this helpful thanks.

Top comments (0)