Throughout this blog, I'll be taking you through a general git workflow. I thought of writing up a blog since I seem to forget common commands pretty often and this would then also serve as a reminder for me.
Throughout this blog, we'll work with EddieHubCommunity's hacktoberfest-practice GitHub repository and push our changes there. Sidenote: Eddie is a great promoter of open source and is passionate about introducing people to open source so if you are new to oss, then consider joining his community.
Click on the Fork button on the top right corner to get a local copy of the repository under your github account
This clones the repository under <your-account-name>/hacktoberfest-practice
[Go ahead with "Copy the main
branch only" checkbox].
What forking does is create a copy of the repository for you to experiment with. Changes that you make to the copied repository won't affect the main repository. In the past, I've made the mistake of thinking that I made changes to the main repository when I actually made changes to the copy.
You've copied the repo. Much success. Now, you need to add your changes but how do you do that locally(locally meaning on your local system)? For that you need to clone the repository onto your local system and then work on it. Cloning essentially downloads the repository folder under the directory where you run the clone command(i.e. your working directory).
[You'll need to have the git cli set up on your local system for this]
You'll be running git clone <url>
for cloning the repo and the url supplied is the url needed to locate your copied repository.
You can also get the url from the code button.
Follow these commands:
git clone <https://github.com/><your-user-name>/hacktoberfest-practice.git
cd <working_dir>/hacktoberfest-practice
# Adding the upstream link
git remote add upstream <https://github.com/EddieHubCommunity/hacktoberfest-practice.git>
# Check your links
git remote -v
On seeing the output you might be confused between upstream
and origin
. upstream
points to the link where the main repository is located and origin
points to your copied repository's link
Also, fetch
is the link needed for fetching changes and push
is the link needed for pushing your changes. You can also change the links stored under fetch
and push
so that you won't be able to work with either (helps in security purposes).
The next step is to get your local master/main branch up to date(It might be called main or master depending on the repository you're working with). All branches except the main/master can be considered as offshoots of the main branch which people work on individually and then push their branch's changes to the main branch.
Before creating our branch, we'll be rebasing our local main branch to reflect all the changes made in the upstream repository's main branch. This ensures that we have the latest version of the upstream repository locally for us to work with. Rebasing essentially means changing the base and hence you'll be changing your base/main branch to reflect the upstream's main branch. More info here