Version Control with GIT

Good day my dear Linux Yogi’s,

in today’s illustration I am going to show you how to get started with GIT Version Control in a very basic way. GIT is a vastly used version control system.

Think of it that you are starting to write a new program or website and you like to version control your progress and lets pretend you have your code in the following path: /home/user/project/new_website.

Now lets ensure you have git installed on your system by running the following command to install git.

sudo apt-get update
sudo apt-get install git

Next go into your directory where you have your coding project like /home/user/project.new_website

cd /home/user/project/new_website

So for git to work properly you need to provide some user information and initialize it. First you need to provide a username:

git config --global "Clark Kent"

then you should provide an email address:

git config --global

the next command will ensure that git uses matching feature set in case you use a remote repository like BitBucket. (The next article will be about using a remote repository with BitBucket)

git config --global push.default matching

and lastly I recommend that you use an alias for the checkout command:

git config --global checkout

finally you are ready to initialize your local GIT Repository,

git init

So your repository is ready and lets think of it that you already have a bunch of source code files in your Project Folder new_website. The following command will add all files to the repository.

git add -A

now that you added your project files lets check the git status with the following command:

git status

and you should receive something like the following:

On branch master

Initial commit

Changes to be committed:
 (use "git rm --cached <file>..." to unstage)

new file: index.html

now to make the changes stick you have to commit them by executing the following command:

git commit -m "Initial commit"

and it should return something like the following:

[master (root-commit) 495956f] Initial Commit
 1 file changed, 1 insertion(+)
 create mode 100644 index.html

If you like to check the status or progress of the repository you can issue the following command:

git log

and you should receive something like the following:

commit 495956f56ec86c1783691eb0a45fc8a2524f09d2
Author: Michael St. John <>
Date: Mon Apr 24 20:40:36 2017 -0600

Initial Commit

So far so good. Now lets imagine you deleted a file or a series of files. Well now that you have this in your repository you can simply checkout your files and be back in business. Run the following command:

git checkout --force

or you can use your alias and short version of the command line switch:

git co -f

Now you have to make sure about the difference between the two following commands. The first one will add only changes of existing files but not newly added files:

git commit -am "Add changes"

the next two commands will add all new files and changes to the repository

git add -A
git commit -m "Added files and add changes"

Okay now lets think you have an idea and want to tinker around with some code but don’t want to touch the existing committed code. In this case you create a branch. The following command checkout out the project into a new branch.

git checkout -b new_brnach

If you like to check on your branches you can execute the following command

git branch

and it should return the following

* new_branch

In the next step lets imagine you added files and committed them to the branch repository and you are satisfied so you like to add the to the master. The following two commands will take care of it. The first command will checkout the master and the second command will merge the branch into the master.

git checkout master
git merge new_branch

and lastly you want to delete the obsolete branch with the following command:

git branch -d new_branch

I think for the basics this should be it. The next article will illustrate to utilize a remote repository and push your project into the remote repository.

If you like this article please subscribe and share it with your friends. If you have any ideas for me to write about use my contact form send it my way.

Until next time, Namaste my friends 😉