Git, GitHub and Open-Source Projects
I’ve had to use GitHub in the past for the ZTM course, as a way to begin posting my projects. So, I was familiar with creating a repository, and using GitHub Pages to have a domain for the repository through GitHub. Now git was something I knew was directly related to this all as I’ve heard it being talked about many times in the past, I just didn’t know the why or how it worked within the realm of version control.
Learning it was actually enjoyable. And the commands were not so difficult to get the hang of.
To start, we want to have Git Bash installed, or being using a developer environment such as VS Code that has a terminal built in. And we want to have an empty dedicated folder that we’ll use when cloning our fork.
When we have a terminal set up that is linked to our developer environment, we will direct our attention to the main branch of a project’s repository. We don’t want to clone the main branch from the main source, instead, it’s good practice to fork the repository so it gets sent to your profile's repositories. From there, we should then clone using either the SSH or HTTP link. I use HTTP.
After copying the link provided, in our preferred terminal we enter “git clone [link]”. When the version gets cloned over to your environment, before editing/adding anything, it’s important that we branch off from the main branch.
To create a new branch, we enter “git checkout -b [branch name]”. This is the branch we want to do our work on. And when we’re done with what we’re doing, it’s good to check the status and see if changes actually registered with “git status” and “git diff”.
After checking our changed branch and feel it’s good to send back to the main branch or to get it reviewed, we can begin sending it back to GitHub repository. Using: “git add .” (period means we’re adding all files, but we may add individual) we can save a snapshot of the project into commit history. Then, we can use “git commit m’[comment here]’ ” to commit to these changes we made in the branch.
Now, to get it actually into the repository on GitHub, we say: “git push origin [branch name]”.
What happens if someone makes an update to the original project while you’re working on your forked branch? From the main branch in your forked repository, you can simply put in your terminal: “git pull upstream main”.
Learning about Git has been a good experience, and it makes me more excited to take on open-source projects since I know have an understanding of how this all works. And applying this new skill to these projects would be a great experience not only to get in the flow of using Git, but also in the flow of being familiar with version control and working with others within the development space.