GitHub is a great platform providing various features for developers to store their work. If you’re a beginner in GitHub, you can follow this simple guide. It covers the guide on how to update GitHub repository.
Follow along with this guide to learn how to add a remote Central Repo to your local repo and get automatic updates sent to your fork. Do this every time before making changes to your local repo.
This article will give you a clear guide on how to update the GitHub repository. You can follow the steps and also customize your repository using commands used in GitHub. Let’s check this out!
Table of Content
Things You Should Know About Updating GitHub Repository
Before starting to update your repository in GitHub, you should perform the following steps:
- Forking the NEONScience/DI-NEON-participants repo to your github.com account.
- Cloning the forked repo and making a copy of it on your local computers.
- Adding files and information to your local copy of the repo and committing the changes
- Sending the updated code to the master branch of your forked repository on GitHub.
- Making your changes available in the master repository by completing a Pull Request.
If you’ve already gotten everything set up to work on your project, you won’t have to go through the fork and clone processes again. But you do want to update GitHub local repository with any changes others may have submitted to the central repository. What should you do?
You can accomplish this by configuring our local repository to act as a “remote,” thereby allowing us to pull the latest updates from the master repository directly into our own. Any repository that is not the one you are working in at the moment is considered a “remote” repository.
Updating Repository on GitHub
Once you’ve established a routine for working in your repository, you should always begin with these steps:
- It is time to pull the latest changes from the master repository and apply them locally (git pull upstream master).
- You can make changes, save, add, and git commit to your local repository.
- Transfer modifications made in your local repository to the one you created on github.com (git push origin master)
- Bring the changes from your fork into the main repository (Pull Request)
Note that you have already covered stages 2-4, and thus by covering how to update GitHub repository local repo directly with any changes from the central repo, you will have completed the full circle.
Following the instructions in the correct order will guarantee that any updates made to the NEON central repository are reflected in your forked and local repositories before being added to the central repo. Creating a merge conflict is more likely if you don’t synchronize in this order.
What is Merge Conflict?
When two or more people work on the same section of a file at the same time, it might lead to a merge conflict. Because Git does not know which change occurred first, it cannot determine which change should be included in the most recent version. And that’s why there’s fighting.
This graphic illustrates the potential for update merge problems. When two or more people make changes to the same section of a script or document at the same time, and Git can’t decide which modification should be implemented, a merge conflict occurs.
When two or more people make changes to the same section of a script or document at the same time. Git can’t decide which modification should be implemented, and a merge conflict occurs.
Configure Upstream Remote
To avoid having to manually check for updates every time you make a change to the local repository, it is suggested to download the files and apply them from the master repository instead. You can add the master repository as an upstream remote to the repo.
Obtaining the Master Repository URL
- The primary archive’s URL is required immediately. To access the main repository, NEONScience/DI-NEON-participants can be found on GitHub. To copy the URL of the repository, click the green Clone or Download button.
Adding the Remote
- Secondly, you need to link our local repository to the upstream remote, which is the main repository.
- You must verify that you are still working in the bash local repository.
- Start by going to the folder you want to access.
|$ cd ~/Documents/GitHub/DI-NEON-participants|
- Then, type the command below:
|$ git remote add upstream https://github.com/NEONScience/DI-NEON-participants.git|
- Here, you’re using the git command to determine that it is a git command and then using the supplied URL to add an upstream remote.
Updating Local Repository
- Sync your local repository with the forked GitHub.com repository using git pull.
- Then, pull changes from the master branch to your local repository using git pull with the upstream and master options (keep in mind that branches are a fantastic tool to investigate after you’re familiar with Git and GitHub. Just use master.
$ git pull upstream master remote: Counting objects: 25, done. remote: Compressing objects: 100% (15/15), done. remote: Total 25 (delta 16), reused 19 (delta 10), pack-reused 0 Unpacking objects: 100% (25/25), done. From https://github.com/NEONScience/DI-NEON-participants 74d9b7b..463e6f0 master -> origin/master Auto-merging _posts/institute-materials/example.md
Every time you update, the output will change. Here are some things to look for in the output:
- remote: …: The number of updated items is displayed on the remote control.
- From https:URL: Although you choose to make the primary repository the remote, this could be any repository.
- Section with + and -: Indicates which documents have been updated and what changes were made (additions or deletions) in a visual format.
Now that your local repository is up to date, let’s have a look at it.
|$ git status|
Now that you have completed the additions, you must add and commit the changes. After that, you can upload the revised version to your github.com fork.
|$ git push origin master|
Once your changes have been committed to your cloned repository on github.com, you can initiate the cycle again by submitting a Pull Request.
Here are some commands on GitHub you can use.
- Clone — A Git repository can be copied using this technique.
$ git clone <repository name>
- Add — Changed files can be saved in the git repository by committing after being added to the staging area.
adding a particular modified file to staging.
$ git add <file-name>
adding all the modified files to the staging area.
$ git add .
- Status — Show the working tree’s status (staged or unstaged files), including any recently updated files.
$ git status
- Commit — Saving changes to the local Git repository.
$ git commit -m “commit message eg- initial commit”
- Push — pushing local updates to a particular remote branch.
$ git push origin <remote branch name>
- Pull — To download and incorporate changes from a distant branch into a local branch.
$ git pull origin <remote branch name>
- Branch — Create a new pointer head on the commits by branching.
$ git branch <branch-name>
- Check-out — Used to switch branches.
Change branch only.
$ git checkout <branch-name>
Change and create the branch.
$ git checkout -b <branch-name>
- Merge — Used for reassembling a split history is to merge. It effectively merges the first branch and the second branch. Adding the feature branch to the master branch, as an illustration.
$ git merge <branch-name>
- Delete — Remove the pointer head from the commits by selecting delete.
Deleting local branch.
$ git branch -d <branch-name>
Deleting remote branch.
$ git push origin --delete <branch-name>
- Rename — Rename branch.
Renaming current branch.
git branch -m <branch-name>
Renaming any branch pointed.
git branch -m <old-branch-name> <new-branch-name>