Basics of GitHub

By Sweta Panigrahi | 01-03-2018 10:57 AM | 1291 | 3

GitHub may sound complicated but once we understand it, it turns out to be no more than a simple social network. It is not very different from Facebook and Google plus. You sign up, sign in, upload projects, download projects, follow other users and many more things that make it very similar to a social network.

What is Git & GitHub?
Let's understand Git first. Linus Torvalds, the man himself created Git, the software that is same for GitHub as a kernel is for an OS. 

Now GitHub. The only problem with Git is that you have to everything by using the command line (terminal / console / konsole). Here comes GitHub. GitHub provides a visual interface to help and manage the project. You can create an account here and it gives more of a social network feel. You can browse through users' profile, check their projects, download a copy of it to your profile or computer or alter it. No data will be lost.

GitHub can be used without command line but there is a difference between using and understanding it. In this post, we will be working with git and GitHub using the command line.

Terms to know:
1. Repository : A directory where we can store our project.
2. Version control: A solution to losing the track of modifications without creating multiple copies.
3. Clone : downloading (cloning) any project to your local system.
4. Fork : A copy of a repository. Allows to modify / edit code without affecting the original project.

Steps to success:

1. Create an account. It is same as creating any social network account. Throw in a valid user name, email id and a password to start.

2. Install Git. if you are going to work in your computer with git, you need to install it. Use one of the following commands to install git.

Fedora users
$ sudo dnf install git-all
Other Red Hat based Linux users
$ sudo yum install git-all
Debian based Linux users
$sudo apt-get install git-all
3. Configure your system to git. As we have already installed git in our system, to configure, just type
$ git config --global "your user name here"
This is the user name git will use to credit commits. Now the email id that was just used to create GitHub account.
$ git config --global "your full email id  here"
4. Create a repository. A repository is  also called "repo" in short. To create a new repository in your account, go to the '+' sign beside your username / profile picture in right-hand side upper corner. On clicking on the sign, from the drop down menu, select new repository.
Now, It will prompt for a repository name. Fill it up. Just below that, add a bit of description about the repository or project (Optional).
Further down to that, select public repository if you want to keep it public and free, or private if you want to keep it a secret (Paid).
Just below that, don't forget to tick that check box that says initialize this repository with a README. Readme is just a text file that is used to store basic information about the project like About, collaborators, dependencies etc. Click "create repository" to proceed.

As this is first-time hands on GitHub, I don't want to confuse everyone with making a local repository. We shall understand those concepts in next workshop.
As of now, lets clone the repository so that we can modify it on our computer and then we will put it on the GitHub using the command line.
Before cloning it, first, go to the directory where you want to clone your repository. Then go the repository you want to clone, and copy the link you get in [Clone or download section].


 To clone, use the link as given below
$ git clone copied_link
 Here is an example of the commands mentioned above
Now, in go in the directory, you will see the cloned repo. Now change the code, etc in whatever way you want. 
Let's say you want to add a text file in the repo, type $touch data.txt  and you have successfully added a file. you can modify it using any text editor and save it. What ever changes you have done, can be seen by typing
$git status

and it will show you all the modifications done.
To add it to the repo as a part of it, type
$git add .

here [dot] means everything that has been changed. You can also mention just the file name you want to add. In our case, &git add data.txt
Now time to save the changes. If you know even basic SQL, you know how to save (commit). Type
$git commit -m "any comment"

commit is the keyword that saves and -m passes the comment parameter that will be seen in time line when having an eagle eye on the versions of the project. 
Now you have saved the file, lets merge it to our repo that is on GitHub. Type
$git push

It will prompt you to enter username and password, fill it and your files are up.
You can go to your repo and check it.

I have tried to keep the post as simple as i could. This is for students who have never heard / used git or GitHub. If you are interested in learning more, leave a comment.
You can also visit this link to learn more about it.


Facebook Google LinkedIn Pinterest Reddit Tumblr Twitter Email Print