Skip to main content

GIT Version Control Tool

This article contains basic commands and usage information of GIT version control tool. GIT is a free and open source distributed version control system designed to handle everything from small to very large projects with speed and efficiency. Version control is a system that records changes to a file or set of files over time so that you can recall specific versions later.

You can download and install GIT from After installation, open git bash from Windows start menu. Just click on your new “Git Shell (or Bash)” Icon and type git commands in the Git “MINGW32” Terminal window.

Initializing a Repository in an Existing Directory

$ cd yourDirectory

$ git init

Start Version Control of Existing File

$ git add myfile.c  //staging modified files

$ git commit -m 'intial project version'

$ git pull origin   //Pull the updates from repository.
$ git push  //Send updates to the repository.
Get a Copy of an Existing Git Repository

$ git clone

Clone The Repository Into a Directory Named Something Other Than "originalname"

$ git clone myarducopter

Checking Status of Your Files

$ git status

$ git status -s  //short status

Ignore Files

edit .gitignore

Viewing Your Staged and Unstaged Changes

$ git diff    //don't show all changes made since last commit- only changes that are still unstaged. If you have staged all of changes, git diff will give no output

$ git diff --staged   //compares staged changes to last commit

Commiting Changes (from stage area to commit)

NOTE: Before commit files be sure that everything was staged (git add)

$ git commit

$ git commit -m "fix 182: fix benchmark for the speed"

Skipping Staging Area

$ git commit  -a -m 'commit all files"   //commit all files that is already trackedbefore doing commit

Removing File

$ git rm myfile.c  //remove file for the staging area

$ git rm --cached myfile   //keep file on the drive but not have Git track it anymore

Moving Files

$ git mv file_from file_to

View Commit History

$ git log

$ git log --oneline --decorate


$ git commit --amend

Undo last commit

$ git reset --soft HEAD~1  //your last commit wasn't a disaster, but just a bit off. You want to undo the commit but keep your changes for a bit of editing before you do a better commit.

$ git reset --hard HEAD~1  //your files are reset to their state before last commit

Unstaging a Staged File

$ git reset HEAD <file>...

Unmodifying a Modified file

$ git checkout -- myfile.c

Showing Your Remotes

$ git remote -v

Adding Remote Repositories

$ git remote add myrepo hhtps://

Fetch all information from remote

$ git fetch myrepo

Pushing to Your Remotes 

$ git push origin master

Inspecting a Remote

$ git remote show origin

Listing Your Tags

$ git tag

$ git tag -l 'ArduCopter*'

Creating Tags

$ git tag -a v1.4 -m 'my version 1.4'  //-a  annotated tag

$ git show v1.4

Tag later

$ git tag -a v1.2 9fceb02

$ git tag v4.1-lw    //lightweight tag

Checkout Tag

$ git checkout -b [branchname] [tagname]:

$ git checkout -b myversion2 v2.0.0

Show tag info

$ git show v1.2

Creating New Branch

$ git branch testing   //it creates branch but it did not switch to that branch

Switching Branches

$ git checkout testing

$ git checkout master    //switch back to tha master

Create Branch and Switch to it At The Same Time

$ git checkout -b mybranch

Clone repository with its submodules

It will automatically initialize and update each submodule in the repository.

$ git clone --recursive

Branch Listing

$ git branch

Merge Master and Your Branch

$ git checkout master

$ git merge mybranch

Delete Branch

$ git branch -d mybranch

$ git branch -D mybranch

Last Commit on The Branches

$ git branch -v

Get the latest updates from remote to your master

$ git fetch origin 

While the git fetch command will fetch down all the changes on the server that you don’t have yet, it will not modify your working directory at all. It will simply get the data for you and let you merge it yourself. 

$ git pull origin 

However, there is a command called git pull which is essentially a git fetch immediately followed by a git merge in most cases. If you have a tracking branch set up, either by explicitly setting it or by having it created for you by the clone or checkout commands, git pull will look up what server and branch your current branch is tracking, fetch from that server and then try to merge in that remote branch.Generally it’s better to simply use the fetch and merge commands explicitly as the magic of git pull can often be confusing.


There is no difference in the end product of the integration, but rebasing makes for a cleaner history. If you examine the log of a rebased branch, it looks like a linear history: it appears that all the work happened in series, even when it originally happened in parallel.

$ git checkout experiment

$ git rebase master    //apply the changes (but not merged yet) to master  

$ git checkout master    //go back the master and fastforward merge

$ git merge experiment  //apply the changes onto master

Show Version Info

$ git show 1c002d

Show branch SHA-1 value

$git rev-parse topic1

Git Log

$git reflog

$git log -g

Cleaning Working Directory

$ git clean

Stash the changes in a dirty working directory away

$git stash

$git stash list    //mevcut olanları görüntüler

$git stash pop stash@{0}   //En son stash sürümünü geri al

Remove files from git

$git rm file.txt

$git rm -r directory_name

$git rm -r -f directory_name   //force to remove directory 

Git ignore

Go to git repository directory

$touch .gitignore  //create gitignore file

Open gitignore file and add  *.obj *.err /directory/subdirectory/

Show URL

$git remote show origin

Keeping a fork up to date 

1. Clone your fork:
git clone
2. Add remote from original repository in your forked repository:
cd into/cloned/fork-repo
git remote add upstream git://
git fetch upstream
3. Updating your fork from original repo to keep up with their changes:
git pull upstream master


git log --all --grep='3.3.3-rc1' // search given text in the logs

Bare Repository

Go to USB stick and related directory and init bare git repository

$ git init --bare

Go to directory where the working directory is and clone the bare repo

$ git clone k:/repo/mynew_repo

$ git remote set-url origin K:/repo/vtol

$ git push --set-upstream origin master

Add files to your working directory and add and commit. then push the files to the bare directory

$git push origin

To get the latest files from bare directory

$git pull origin

Remove ceritficate error during clonning

$ GIT_SSL_NO_VERIFY=true git clone https://yourRepository