Updating the Main Branch
If you just cloned your repo for the first time, you're using the most up-to-date version as your start point. However, if you cloned it a while ago, or this is not your first time contributing, you may not be up to date. So, before you begin, you want to make sure the main branch is current.
To create a new branch or move between existing branches, you'll checkout the branch you'd like to switch to. The checkout command allows you to switch to a new branch, by creating it in the process, or to switch to an existing branch.
To update main, first checkout main to verify you're on the correct branch:
git checkout main
Next, we're going to utilise the original project remote we created. To get the updates from the remote repo, we're going to use fetch. fetch
grabs the the newest version of the remote repo, but does not merge it into the current repo.
Remember, you named the original project's remote repo with the owner's GitHub ID. You'll use this name when you merge the two main branches together. Since I cloned an Adafruit repo, I'll be using adafruit
.
To fetch the updated remote, enter the following fetch
command, replacing ownerID
with the name you assigned to the original project's remote repo:
git fetch ownerID
Now we're going to merge the current data into our local repo. A merge takes the information from one branch and combines it into another. In this case, it's going to take the current version of main from the remote repo and combine it with the main branch on your local repo. This will bring you even with the remote main, and that means you're up to date.
To merge the remote main with your main, run the following merge
command, replacing ownerID
with the name you assigned to the original project's remote repo:
git merge ownerID/main
There have been some updates to the remote main since I last did anything with this repo. Good thing I updated!
Now your main branch is even with the original project's main branch and you're ready to create your working branch!
Alternatively, you can simply run git checkout ownerID/main
(where ownerID
is the name you assigned the original project's remote repo) and then continue with the next set of steps. It will not update your main branch, but it will ensure that you create your new branch from the most updated version of the repo.
Text editor powered by tinymce.