Everyone can rock Git and GitHub, even beginners. This piece seeks to present a step-by-step analysis from accumulated learning platforms and media, on how to absolutely get rocking with Git and GitHub even if this is the first article in which you have ever read about it.
What is Git and Github?
Firstly, imagine if your final year project containing thousands of lines of codes got wiped out by a malignant virus on your computer. Or your best friend (that is your hard drive) got stolen or was misplaced. That would be terrible yeah? “But Google Drive for example can help solve that problem”, you may say. Yes, that’s true. But there’s so much more to GitHub than storing.
Git was developed in 2005 and is an extremely popular version control system that is used by a lot of developers. It enables you to keep track of various versions of your development project.
For example, if you were working on a mobile application and on version 1.0 there isn’t a Geolocation feature; which is present in version 1.2. However, as you continue your dev journey, you realized there was a specific function in the previous version 1.0 you have lost track of and needed; what do you do then?
Well Git is there to ensure that doesn’t happen as it allows you to keep track of all versions and more.
Git is installed and maintained on your local workstation/pc and is very responsive, easy to use and free. One of its unique features is its branching model. This is the ability of Git to let you create local branches/model in your code. This typically allows you to dive out of and test out various ideas and concepts.
GitHub on the other hand is a repository for your Git Version Control. It is a very important developer tool that helps you host, edit, share and keep track of your code. As implied, it is located on the cloud and is usually used for collaborations on various projects.
While GitHub is not totally free, basic features are available to the general public and developers.
GitHub also has a very intuitive Graphical User Interface and also extends the basic functionality of Git. GitHub Also allows you to implement additional features through its marketplace and do much more.
More on Git and GitHub
In the hustle for the cure of COVID19 for example, individual scientists make a lot of research and test several samples. But then they take their research analysis and samples to a lab where many other scientists also bring theirs so they can cross-evaluate and make amends.
This is exactly like Git and GitHub. While your codes and materials represent your samples and research, Git is that mechanism like a car that enables you as a scientist get to that lab. Then, GitHub is the lab where you don’t only get to store your samples and save your research but also get to have other coders like you, work on your works, make amends (if you want them to), track progress and a lot of other things.
While this piece will not be exactly for defining Git and GitHub, or discussing the versions we have, this clear analogy completely encompasses what we need to know about what exactly these things are.
Differences Between Git and GitHub
The differences between Git and GitHub have been summarized in the images below.
Now let’s get rocking!
Getting Started with Git and GitHub
There may be a number of methods with which individuals work with Git and GitHub. But I will be sharing the most conventional method I have learnt: using Git on your local machine with Bash and then GitHub. Have your computer close to you, this will really be an eye-opener.
N.B: Once you’ve downloaded and installed git properly, the next 5 steps are things you always do locally on your computer without necessarily connecting to the internet. Steps 6 and 7 contain working with the repositories on GitHub and for these, you’d need to connect to the internet.
1. Install Git.
First thing you would want to do is to download and install Git on your local machine (laptop/desktop) in other to be able to run it. You can do that via this link: https://git-scm.com/downloads. Download with respect to your OS. After a successful download, then we have to install. You will want to leave all already checked boxes the way they are and probably just click “Next”. These are the recommended options that the developers think will work best for you. Once done, two options pops up on the finish page: View release notes (meaning that it automatically opens the notes about the version and so on) and Launch Git Bash. Git Bash is like the Command Prompt of Git. Remember that thing “cmd” that you input when you enter windows key+r? Yeah, Git has its own. And it’s quite better to use. So, check the box to launch it.
2. Create your environment.
Open a folder where you want to save everything you will like to get to GitHub. Then you can right-click on the folder or inside the folder and a new option will appear on the drop-down menu: “Git Bash here”.
Click on that, and the Bash window comes up.
Restore down your folder window and place it side by side with the Bash window so you see exactly what happens. You can use the command:
to check the version of your git.
3. Kick Off with the commands.
You can create different files in a folder right there on Bash using the command: touch. So, if you want to create a file index.html for example, you type
and click enter. You will see an instant appearance of an html file named index in the folder you opened.
Then, you have to initialize git in that folder. This tells git that you need it in that folder so it can help you transfer the contents of that folder to the Hub. Use the command
When you click enter, nothing appears but it’s fine. If you change the View setting in your folder to view hidden files, you will see the git folder appear there. But no stress, you can as well leave it.
Next up, add your name and email address to config your git in that folder. Use the commands:
git config --global user.name ‘put your name here’ git config –global user.email ‘put your email here’
You have to do this individually and click enter each time.
4. Start Adding and Staging.
Once you have git initialized, it doesn’t collect the files in the folder to a staging area except you tell it to do so. A staging area is a section in your local machine where the files go before they are sent to the Hub. To take them to staging area, you use the command: git add. If you want to add all the files in that folder to the staging area:
But if you just want to add a specific one:
git add filename
But if you want to add probably all html files in that folder:
git add .html
with an asterik * before the .html. More and more techniques exist. Once you do this, you can check the status of the things that are in the staging area using:
If you see any file name in red, it means that such file is in the folder but has not been added to the staging area.
5. Committing is important.
After adding the files to the staging area, git recognizes the contents of the files as at that time. So, if you modify the file and maybe change something in it, git recognizes that as well. After modification, if you check the status, it will show that a change has been made and that change hasn’t been added.
So, after a very major change, when you’re done with the work, you will need to run the git add command again, just like you use ctrl+s on Word. Then, just like adding comments to your codes to have a better understanding even after writing them, we use commit in git.
This shows that you’re done with a particular section and you are ready to commit the works in the staging area to the Hub. You can always add a message too. So, if you just finished designing you login form and you have added it, you can commit it and add a message:
git commit -m ‘just finished my login form’
and click enter. You can run the git status again to see the state of your staging area, you’d probably see “nothing to commit, working tree clean”.
6. Connecting with the Hub
The first thing you would want to do is to own a GitHub account. You can do that here: https://github.com/ . Once you verify your email and all, then you are good to go.
Next up is to create a Repository (a.k.a Repo). This is like having different folders on a desktop. It stores and arranges your files and works in different places. So just like you can always create a new folder, you can also create a new repo.
At the top bar on your GitHub account, close to the notification icon, you’ll see a plus icon with a dropdown arrow. Click on it and select “new repository”. Choose your repo name and see if it is available. Put a description if you want.
To make the repo private, that means only you or the people you allow to can view the repo and its contents, but this comes with a fee. Then, you either check the box to initialize a README.md file or not. This is often like an attachment to a parcel where you can talk about the repo and what you want the observers to see and know.
Quick setup page comes up. But this only comes up when you don’t initialize a README.md file. The page shows you some info on how to create the file from your bash or command line using the touch command we learnt earlier. It also contains hints on how to link your git and your GitHub.
7. Link your repo and push.
Once you’re done with all the adding and committing, it is then time to send everything to your new repo. To do this, on your bash, input the command:
When you click enter, it won’t really bring up anything. Its fine.
Next up, link you repo:
git remote add origin https://github.com/xx/yy.git
(where xx is your username and yy is your repo name; the link will be right there for you.) then click enter.
Enter git remote again, this time it’d show origin. It is now time to push.
Use the command:
git push -u origin master
It’d load for a while then bring up a page to input your username and password. Once these are confirmed, all the files that are on the staging area and have been committed will go straight to your repo. It’d show on the Bash once this is done. Then you can go ahead to reload your GitHub page, then you’d see the contents inside the repo.
**After the initial login, for every new amendment you make and you’ve added and committed, you won’t have to relog in. You just the command:
Yeah! That’s something, yeah? It’s all fun. While some individuals may use drag and drop methods on GitHub, it is very important to learn to use git properly. A whole lot of tech companies these days give more chances to guys that can use tools like git. More importantly, there are a whole lot to use git for.
Check out a list of all the basic commands we’ve covered thus far:
git --version (to check version) touch filename (to create a file) git init (to initialize git in a folder) git config --global user.name 'name' (to add your name to the git environment) git config --global user.email 'email' (to add your email to the git environment) git add filename (to add a file) git add .html ; with an asterik before the .html (to add all html files) git add . (to add all files) git status (check state of tagging area) git commit -m ‘message’ (committing and adding a message to the staging area) git remote (checking out you linked remote network) git remote add origin https://github.com/xx/yy.git (add your repo) git push -u origin master (pushing from your computer to your repo) git push (pushing to your repo after first log in)