Sign in
Log inSign up
A Beginner’s Guide To Git And Github

A Beginner’s Guide To Git And Github

Including links to resources for learning git.

Jyoti Bisht's photo
Jyoti Bisht
·Apr 29, 2021·

4 min read

Learn Git!. Who ever told you so, did the right thing. As a beginner, it can be a bit tough to understand what is happening, especially when you try to use git from the command line but - I got you covered!. At the end of this article, I will be attaching links to git commands cheat sheet and git tutorials which you can refer to when working with git later - but first, we need to understand how it works (trust me, it will be interesting).

What is git? In official terms, git is a free , open-source , version control software invented by Linus Torvalds (the creator of Linux) in 2005.

What is version control? Lets be honest, as a developer, there is always an improvement done/needed in our project. We initially create a project, then improve it and save it as “final” , then we make changes again and now save it as “final_for_sure” and the saga continues.

But what if we are working in a team or we decided that the project “final” was better than “final_for_sure” and we want to revert the changes?. It becomes difficult to do these things with the conventional file system. Hence, the idea of a version control system was proposed which meant now there was a system to track the versions we released for our project. Hence , with a version control system, we can easily see who made what changes to our project, when were those done and even revert the changes etc. more examples of version control software - mercurial, SVN , CVS etc.

What are git repositories or repos? They are just the projects you upload to git.

Is git only available on Github? No, you can use BitBucket or GitLab too. While github is widely popular, it is not the only option.

Working with github

For basic things like creating an account on github, creating a new repo, please refer this link -> tutorialspoint.com/how-to-create-a-github-… You need to install git on your system to work with it. It can be downloaded from -> git-scm.com/downloads

In your repo, you would see a green button saying “clone or download”. We need to click on it and get the URL present there. To work with our project and make changes in it, we need to get a copy of it in our local system, or in other words “clone” it. Moving on to our terminal, type the following command:

git clone [URL]

We are slowly learning to work with git commands. Git commands begin with “git” and each of them has a specific dedicated function it does. So, now the project is cloned on to our laptop/ local system, we can work on it and make changes to it. Open the folder now where the clone resides.

cd [name of the folder]

Now let us say we made a change in our project. Now we need to save it right? And we need to only ensure that the change is not only made in our local system but also in github where the original project is hosted. This is something called as “commit” i.e. to commit the changes in the original project. For making a commit, there are 4 stages required to be completed -> ‘status’, ‘add’ , ‘commit’ and ‘push’.

  • Status - there can be a lot of files in our project and we might have made a 100+ changes. Now we need to see them all -> git status does that for us.

  • Add - add the files to be committed. For example, out of 10 files modified, we need to commit only 5 files and the changes made to them. For this we could do:

git add [FILENAME 1] [FILENAME 2] [FILENAME 3] [FILENAME 4] [FILENAME 5]

But if we are sure as to commit ALL the files , we need to add all of them which can be done with:

git add .

Git add adds everything to the staging area.

  • Commit - when working with a team, we need to make sure they understand what changes we made and this is done by simply leaving a message with the commit. It is similar to texting your co-maintainer “hey, i just made a change which can be found at line 38”. This is done with :
git commit -m “message”

Writing good commit messages is a skill and an in-demand one in the world of open source and development.

- Push - ready to put our code out in the world!. But we need to push it in remote-> git remote tells you the branch we need to push it on.

git push [name of branch] master.

You just made your very first commit and learned about git and github. But , there’s more. Below are the list of resources which will help you master git and github.

That was it! Feel free to leave any doubts, suggestions or feedbacks!.