Install GIT to Create and Share Your Own Projects on GITHub Repository

If you have spent any amount of time recently in the Linux world, then chances are that you have heard of GIT. GIT is a distributed version control system that was created by Linus Torvalds, the mastermind of Linux itself. It was designed to be a superior version control system to those that were readily available, the two most common of these being CVS and Subversion (SVN).

Whereas CVS and SVN use the Client/Server model for their systems, GIT operates a little differently. Instead of downloading a project, making changes, and uploading it back to the server, GIT makes the local machine act as a server.

Install GitHub in Centos

Install GitHub Repository

In other words, you download the project with everything, the source files, version changes, and individual file changes right to the local machine, when you check-in, check-out, and perform all of the other version control activities. Once you are finished, you then merge the project back to the repository.

This model provides many advantages, the most obvious being that if you are disconnected from your central server for whatever reason, you still have access to your project.

In this tutorial, we are going to install GIT, create a repository, and upload that repository to GitHub. You will need to go to http://www.github.com and create an account and repository if you wish to upload your project there.

How to Install GIT in Linux

On Debian/Ubuntu/Linux Mint, if it is not already installed, you can install it using apt-get command.

$ sudo apt-get install git

On Red Hat/CentOS/Fedora/ systems, you can install it using yum command.

$ yum install git

If you prefer to install and compile it form source, you can follow below commands.

$ wget http://kernel.org/pub/software/scm/git/git-1.8.4.tar.bz2
$ tar xvjf git-1.8.4.tar/bz2
$ cd git-*
$ ./configure
$ make
$ make install

How to Create Git Project

Now that GIT is installed, let’s set it up. In your home directory, there will be a file called “~/.gitconfig“. This holds all of your repository info. Let’s give it your name and your email:

$ git config –-global user.name “Your Name”
$ git config –-global user.email [email protected]

Now we are going to create our first repository. You can make any directory a GIT repository. cd to one that has some source files and do the following:

$ cd /home/rk/python-web-scraper
$ git init

In that directory, a new hidden directory has been created called “.git“. This directory is where GIT stores all of its information about your project, and any changes that you make to it. If at any time you no longer wish for any directory to be a part of a GIT repository, you just delete this directory in the typical fashion:

$ rm –rf .git

Now that we have a repository created, we need to add some files to the project. You can add any type of file to your GIT project, but for now, let’s generate a “README.md” file that gives a little info about your project (also shows up in the README block at GitHub) and add some source files.

$ vi README.md

Enter in info about your project, save and exit.

$ git add README.md
$ git add *.py

With the two above commands, we have added the “README.md” file to your GIT project, and then we added all Python source (*.py) files in the current directory. Worth noting is that 99 times out of 100 when you are working on a GIT project, you are going to be adding all of the files in the directory. You can do so like this:

$ git add .

Now we are ready to commit the project to a stage, meaning that this is a marker point in the project. You do this with the git commit “–m” command where the “–m” option specifies a message you want to give it. Since this is out first commit of out project, we will enter in “first commit” as our “–m” string.

$ git commit –m ‘first commit’

How to Upload Project to GitHub Repository

We are now ready to push your project up to GitHub. You will need the login information that you made when you created your account. We are going to take this information and pass it to GIT so it knows where to go. Obviously, you’ll want to replace ‘user’ and ‘repo.git’ with the proper values.

$ git remote set-url origin [email protected]:user/repo.git

Now, it is time to push, ie copy from your repository to the remote repository. The git push command takes two arguments: the “remotename” and the “branchname”. These two names are usually origin and master, respectively:

$ git push origin master

That’s it! Now you can go the https://github.com/username/repo link to see your own git project.

If You Appreciate What We Do Here On TecMint, You Should Consider:

TecMint is the fastest growing and most trusted community site for any kind of Linux Articles, Guides and Books on the web. Millions of people visit TecMint! to search or browse the thousands of published articles available FREELY to all.

If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.

Support Us

We are thankful for your never ending support.

Rob Krul

Rob is an avid user of Linux and Open Source Software, with over 15 years experience in the tech geek universe. Aside from experimenting with the many flavors of Linux, he enjoys working with BSDs, Solaris, and OS X. He currently works as an Independent IT Contractor.

Your name can also be listed here. Got a tip? Submit it here to become an TecMint author.

RedHat RHCE and RHCSA Certification Book
Linux Foundation LFCS and LFCE Certification Preparation Guide

You may also like...

3 Responses

  1. Jason says:

    You made one small mistake. If the user has never setup git before he/she will need to do this instead of apply the set-url:

    git remote add origin [email protected]:user/project.git

  2. Rick Copley says:

    I followed this and I am unable to see the repo, unless I create it on github.com first.

    When I create on github.com first, it provides a list of commands that I can then use for the repo:

    mkdir my-forth-git-repo
    touch README.md
    git init
    git add README.md
    git commit -m “first commit”
    git remote add origin [email protected]:username/my-forth-git-repo.git
    git push -u origin master

    • Yoander says:

      If you want to start a clean and fresh project then you don’t need to follow this bunch of steps, firt create the repo on github.com and after do a git clone [email protected]:username/my-forth-git-repo.git and from here you’re under control.

Got something to say? Join the discussion.

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.