What is Github?
Github’s Wikipedia page defines it as below,
GitHub is a web-based Git repository hosting service, which offers all of the distributed revision control and source code management (SCM) functionality of Git as well as adding its own features.
That’s quite a mouthful. Basically Github is a web platform where you can store the source code of your project in any programming language. It supports almost all the commonly used programming languages ranging from Python, Java to Ruby and Perl. The folder in which you store your project source code is called Repository. Github uses Git repository hosting service which makes management of your code easier and you can see the change history of your source code too.
What is Git?
Git is a distributed revision control system with an emphasis on speed, data integrity, and support for distributed, non-linear workflows. Git was initially designed and developed by Linus Torvalds for Linux kernel development in 2005, and has since become the most widely adopted version control system for software development. So let’s learn how to use Github through the Git shell.
Step 1: Create a Github account
Register on Github in the usual way and when you will have an account you will see the following toolbar at the top of your account page.
Step 2: Create a New Repository
Click on “Repositories” tab and click on “New” as shown in the above image. Fill in the repository details as shown above. In the Add a license dropdown choose “MIT” as the license. To know more about licences you can visit http://choosealicense.com/ . After creating the repository, you will see the following page The repository is initialised with 2 files : “README” ,which holds the description of your project and “LICENSE”, which is the document which tells other developers how they can use your project with specific rights and give credit back to you. Now in the above image, see the bottom right corner which has the heading “HTTPS clone URL” . THis URL is used in the Git shell to clone the repository to your computer’s local Github folder. Note: This article assumes that Git is installed on your system. For instructions on installing Git on your PC visit : https://help.github.com/ and click on “Set Up Git”.
Step 3: Open the Git Shell on your PC.
Now you will learn about the most commonly used Git commands in the sequence of their usage below.
This command is used to create a local copy of your repository on your system. When you will open Git Shell, it will show the following The path points to the local folder where your Github repositories will be stored on your system. Now, remember the HTTPS clone URL we discussed above, copy that URL and then write the following command in the shell
git clone https://github.com/YOUR-USERNAME-HERE/test.git
When you press Enter after writing the command, your shell should give similar output as above.
Now write ls in the shell and you will see your repository “test” in the output. ls is the list command which lists the contents of the folder.
Now, use ‘cd’ command to change directory as below.
You can see the path changed to your repository’s folder. After that you can execute ls command again to see the contents of your repository successfully cloned to your local ‘test’ repository folder.
Now when you code anything on your system you can save it in the test folder.
Let’s make a new file in the “test” folder. I have named the file “sample_code.txt”. You can choose whatever name you want to give to it.
After creating the file, you can execute “ls” command again to see your file listed as below.
Add command is used to track all the changes made to the folder.
Status command is used to check the status of the repository and compare the local and the online version of your repository.
You can see the output of the status command . It says “Changes to be committed”.
Commit command is used to record changes to the repository. You can think of commit as an entry in a list of changes made to your project.
We also give a message along with a commit command so that we can remember what change we did when we check that commit later. Message is given in the -m argument.
git commit -m "added sample_code.txt"
Push command is used to update the online repository with the changes made to the local repository. Basically it uploads the added files to the online git repository.
Now you can see you online repository, it will have the sample_code.txt file listed there.
You can also see the message you gave during commit command listed with the file.
That was a beginner tutorial to Git.
You can post any doubts/suggestions/comments you have in the comments section below.