Working locally with git

Dmitrii Korolkov

#Working with the existed project and files

On the previous guide we have installed the git on our Linux distribution. Now it’s time to work with git locally. 

Download the demo project from here and create a folder with files, for example:


In the directory we will see the list of files, for that $user@user:~/Projects/website: ls

Now we are in the folder of our project where all of the files are listed. We need to initialize git within that folder, for that $git init

We will get initialized project folder with ./git prefix at the end of the command line, for example /home/user/Projects/website/.git/

You can also use $git init [project name] but [project name] is optional, just make sure you are in the working folder, $pwd just to

 identify where are you at. You can find all git files, including hidden ones by typing $ls -a

#Projects from zero

Ok, how about starting the project from scratch? Let’s do it!

I am navigating to my project directory and use the command $git init my-project to initialize the folder with git. For now, the folder is empty and doesn’t have any files, so let’s create one. You can use command $your-text-editor, where $your-text-editor will provide the available text editor, in my case it will sublime.

#Submitting the file to Staging Area

So, I am going use $subl – and it will invoke the file extension with .md. In the file we can say pretty much anything we want,  so I’ll include:

#Some comment 

This is the simple text line in the readme file.


Alright, after we can use command/ctrl + W to save the changes in the mark down file. Now, if we say $ls, you will see that is now available in the folder. But, we didn’t add the file to the staging area yet, we can ensure in that by running $git status command. It will inform us, that there is one untracked file that we just created – So, let’s go ahead and put this file into staging area by  running command $git add YOURFILE, in my case it’s going to be $git add

Great! The terminal says that there is some changes to be committed. Let’s do our first commit by running $git commit. You can also add -m “Your Text” to add the text/status after commit has been released. Cool, now there are no files to be committed, the working tree is clean, we can come back to the git and continue working with files.

#Making changes on committed files

Let’s say you need to change the file you already submitted, how are you going to do that? By modifying the README file we will get modified status from git, in order to “apply” the changes to the file in the git working directory, simply use $git add You can ensure that the file was modified by $git status

Now, let’s submit the commit using $git commit -m “Yaaay, file is committed”. How about make the process a little bit faster? Assuming that the file was already committed before, we can just use $git commit -am “Yaaay, file is committed!”. So what it does is adding the file -a, and sending the message after commit was applied. Cool stuff!

#The files that have been modified, more than 1:

In case there are several files that needs to be added or committed, we can use “.” as simple as that: $git add . or $git commit 

#If we would like to remove the files from the staging:

$git reset HEAD yourfile.extension

#Backout Working Directory Changes: 

$git checkout — file-name

You this command in case you would like to back out any changes that were committed to the file and replace it with the old version. 

#Adding all the files: 

$git add .

The period after the command will recursively add all of the files .

Great, now let’s think that we want to remove, or delete the file in the directory, how would we do that? There are different command which are most used: $git rm file.extension / $git commit -m “I am bored of the file, removing it!” Here, we are removing the file and with -rm and submit the commit using commit -m”Our message”. Simple, right? But how we are going to deal with the file that was removed out of git eye? Easy – just add the recursive update: $git add -u. For example, $rm myfile.extension / $git add -u. Git will update and understand that the file was removed by updating the index of the working directory.

proudly runned on WordPress