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 read this far, tweet to the author to show them you care. Tweet a thanks
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.

Each tutorial at TecMint is created by a team of experienced Linux system administrators so that it meets our high-quality standards.

Join the TecMint Weekly Newsletter (More Than 156,129 Linux Enthusiasts Have Subscribed)
Was this article helpful? Please add a comment or buy me a coffee to show your appreciation.

3 thoughts on “Install GIT to Create and Share Your Own Projects on GITHub Repository”

  1. 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

    Reply
    • 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.

      Reply

Got something to say? Join the discussion.

Thank you for taking the time to share your thoughts with us. We appreciate your decision to leave a comment and value your contribution to the discussion. It's important to note that we moderate all comments in accordance with our comment policy to ensure a respectful and constructive conversation.

Rest assured that your email address will remain private and will not be published or shared with anyone. We prioritize the privacy and security of our users.