Git basics: terminologies, working flow and Initialize a new repository

Assuming that you are familiar with version control and have some basic idea about git terminology like git origin/remote etc. For those, who are very beginner and new to git, Here I am trying to explain few terms used while using git:

Working Directory: working directory is a directory on your local system in which you are working.

Remote: remote is any other location where your repository exists and you pull,push changes using ssh or https.

Origin: It’s just an alias to your remote repository url.

git remote add origin remote_location_url

Whenever you write above command, Actually you are telling your local git that your remote repository exists at this location(remote_location_url). As a repository location url can be any long url and it’s not easy to remember and type the url every time. So we give this URL(repository url) a name and the name is “origin”. It can be any name not only the origin. For example:

git remote add mylocation remote_location_url

And when you want to pull or push a branch, you have to use the same name you used while adding the remote location. And that is because, the name you set is an alias to your repository url.

Basic Flow:

As we know that git is a version control. It keeps an eye on every file which is under version control. If There is any file in your working directory but not under version control, git will not track that particular file and mark  as untracked. Any changes done in an untracked file will not be tracked by git. If you want that git will start tracking a file, you have to add it to version control. Here git add command come to the front. When you add a file using the “git add” command, the file will be marked as added/modified based on its status, and git will start tracking the file.


git basics-11

There is a commit area in the git version control system. When we use the “git commit” command, The files from the staging area will be copied to the commit area. Now you have two copies of your files. One in your working tree and another in your commit area. When you make any commit, every commit is assigned an unique commit ID. This commit ID is used to track the changes, rollback your changes.

git basics-21

Now you can push commits to remote repositories. So here is the complete flow:

git basics-31

Here I listed some basic git commands which are frequently used while using git in a project.

Getting a repository: There can be two cases when you work on a project. If your project is not under version control then you can add your directores/files to a repository by initializing git in the project directory. Another scenario is when you start working on a project which is already under git version control and you have to download/clone the repository at your local machine.

Case 1: Initialize a new repository

Go to project directory

cd /home/Desktop/project_directory

Initialize project

git init

Add files to git

git add *.c

Commit files

git commit -m “commit message”

Add origin: add your repository

git remote add origin

Push commits

git push -u origin master

Case 2: clone an existing repository

Go to project directory

cd /home/Desktop/project_directory

clone from existing repository

git clone

When you execute git clone command, this will also create a directory under your project directory. If you don’t want to create an additional directory under project directory, you can use dot at the last of git clone command as shown below.

git clone .

Here are some other articles related to git: Git-Common use cases: branch, revert, logs Git-Tags , git stash

Leave a Reply

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

Back to Top