Installing and Using Git on Ubuntu
GitHub is a treasure trove of some of the world’s best projects, built by the contributions of developers all across the globe. This simple, yet extremely powerful platform helps every individual interested in building or developing something big to contribute and get recognized in the open source community.
This tutorial will be a quick setup guide for installing and using GitHub and how to perform its various functions of creating a repository locally, connecting this repo to the remote host that contains your project (where everyone can see), committing the changes and finally pushing all the content in the local system to GitHub.
Download and install Git for Linux:
sudo apt-get install git
Once the installation has successfully completed, the next thing to do is to set up the configuration details of the GitHub user. To do this use the following two commands by replacing “user_name” with your GitHub username and replacing “email_id” with your email-id you used to create your GitHub account.
git config --global user.name "user_name" git config --global user.email "email_id"
Create a folder in your system. This will serve as a local repository which will later be pushed onto the GitHub website. Use the following command:
git init Mytest
If the repository is created successfully, then you will get the following line:
Initialized empty Git repository in /home/admin/Mytest/.git/
This line may vary depending on your system.
Mytest is the folder that is created and “init” makes the folder a GitHub repository. Change the directory to this newly created folder:
Now create a README file and enter some text like “this is a git setup on linux”. The README file is generally used to describe what the repository contains or what the project is all about. Example:
You can use any other text editors. I use gedit. The content of the README file will be:
This is a git repo
This is an important step. Here we add all the things that need to be pushed onto the website into an index. These things might be the text files or programs that you might add for the first time into the repository or it could be adding a file that already exists but with some changes (a newer version/updated version).
Here we already have the README file. So, lets create another file which contains a simple Python program and call it sample.py. The contents of it will be:
print 'Hello, world!'
So, now that we have 2 files README and sample.py
add it to the index by using the following 2 commands:
git add README git add smaple.py
Note that the “git add” command can be used to add any number of files and folders to the index. Here, when I say index, what I am refering to is a buffer like space that stores the files/folders that have to be added into the Git repository.
Once all the files are added, we can commit it. This means that we have finalized what additions and/or changes have to be made and they are now ready to be uploaded onto our repository. Use the command:
git commit -m "some_message"
e_message” in the above command can be any simple message like “my first commit” or “edit in readme”, etc.
And that’s the basic usage of Git on Ubuntu (also applies to most Linux distros as well).