Git Commands & Workflows

Git – 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.

Uses –

  • Easily recover files.
  • Who introduced an issue and when?
  • Rollback to previously working state

A distributed version control system (DVCS) is a type of version control where the complete codebase — including its full version history — is mirrored on every developer’s computer. It’s abbreviated DVCS.

Features –

  • Distributed System
  • Compatibility
  • Non-linear Development
  • Branching
  • Lightweight
  • Speed
  • Open-Source

Why git ?

There are two main reasons to learn git –

  • Track changes to your code
  • Save your code to the cloud

 Tracking changes to your own code is very important. It allows you to do a variety of things such as:

  – Maintain different versions of the same software (like different versions of an app)

  – Make sure you never lose any code, recover code changes at any point of time.

  – Collaborate with others

Installation –

Download git for windows

  • Browse to the official Git website: https://git-scm.com/downloads
  • Click the download link for Windows and allow the download to complete.

Fig 1:

Extract and Launch Git Installer

  • Browse to the download location (or use the download shortcut in your browser). Double-click the file to extract and launch the installer.

Fig 2:


  • Allow the app to make changes to your device by clicking Yes on the User Account Control dialog that opens.

Fig 3:

  • Review the GNU General Public License, and when you’re ready to install, click Next.

Fig 4:

  • The installer will ask you for an installation location. Leave the default, unless you have reason to change it, and click Next.

Fig 5:

  • A component selection screen will appear. Leave the defaults unless you have a specific need to change them and click Next.

Fig 6:

  • The installer will offer to create a start menu folder. Simply click Next.

Fig 7:

  • Select a text editor you’d like to use with Git. Use the drop-down menu to select Notepad++ (or whichever text editor you prefer) and click Next.

Fig 8:

  • This installation step allows you to change the PATH environment. The PATH is the default set of directories included when you run a command from the command line. Leave this on the middle (recommended) selection and click Next.

Fig 9:

Server Certificates, Line Endings and Terminal Emulators

  • The next option relates to server certificates. Most users should use the default. If you’re working in an Active Directory environment, you may need to switch to Windows Store certificates. Click Next.

Fig 10:

  • The next selection converts line endings. It is recommended that you leave the default selection. This relates to the way data is formatted and changing this option may cause problems. Click Next.

Fig 11:

  • Choose the terminal emulator you want to use. The default MinTTY is recommended, for its features. Click Next.

Fig 12:

Additional Customization Options

  • The default options are recommended, however this step allows you to decide which extra option you would like to enable. If you use symbolic links, which are like shortcuts for the command line, tick the box. Click Next.

Fig 13:

  • Depending on the version of Git you’re installing, it may offer to install experimental features. At the time this article was written, the option to include interactive options was offered. Unless you are feeling adventurous, leave them unchecked and click Install.

Fig 14:

Complete Git Installation Process

  • Once the installation is complete, tick the boxes to view the Release Notes or Launch Git Bash, then click Finish.

Fig 15:

How to Launch Git in Windows

Git has two modes of use – a bash scripting shell (or command line) and a graphical user interface (GUI).

Launch Git Bash Shell

To launch Git Bash open the Windows Start menu, type git bash and press Enter (or click the application icon).

Fig 16:

Launch Git GUI

To launch Git GUI open the Windows Start menu, type git gui and press Enter (or click the application icon).

Fig 17:

Three stage architecture –

We have 3 areas in the Three-stage Architecture:-

Working Directory: The working directory is the folder in your local computer where the project files and folders are stored.

Staging Area: The staging area has those files who are supposed to go to the next commit. Only those files which are needed to go to the next commit stay in the staging area. Like, suppose you are working on that previous project and you have upgraded the index.html file but somehow you broke the engine.js file, so now you will just add the index.html file to stage area so it can be added to the next commit and the engine.js will be used from a previous version. And as you have not staged the broken engine.js file, the broken fill will not be committed.

Git Repository: Git repo is a hidden file named .git. It stores all the commits and compresses them. So when you need a specific commit it can present that to you.

Commands –

git config – This command sets the author name and email address respectively to be used with your commits.

  • $ git config –global  user.name

Example – $ git config  –global user.name “Harry”

  • $ git config –global  user.email

Example – $ git config –global  user.email harry@gmail.com

git init – This command is used to start a new repository.

git status – This command lists all the files that have to be committed.

git remote – This command is used to connect your local repository to the remote server.

Example – git remote add [variable name] [Remote Server Link]

git pull – This command fetches and merges changes on the remote server to your working directory.

Example – git pull [Repository Link]

git clone – Git clone is a command for downloading existing source code from a remote repository (like Github, for example). In other words, Git clone basically makes an identical copy of the latest version of a project in a repository and saves it to your computer.

git fetch – The git fetch command downloads commits, files, and refs from a remote repository into your local repo.

Git branch – This command lists all the local branches in the current repository.

git branch [branch name] – This command creates a new branch.

git branch -d [branch name] – This command deletes the feature branch.

git checkout – The git checkout command lets you navigate between thebranchescreated by the git branch .

example – git checkout <branch name>

git checkout -b <branch name> It creates a new branch and switches to that created branch.

git add – This command adds a file to the staging area.

example – git add <filename>

git commit – This command records or snapshots the file permanently in the version history.

example – git commit -m “<comment>”

git push – The git push command is used to upload local repository content to a remote repository.

example – git push <remote> <branch name>

           git push –set-upstream origin branch_name

git log – The git log command displays a record of the commits in a Git repository.

example – git log

                   git log –oneline

git revert – The git revert command is used for undoing changes to a repository’s commit history.

example – git revert <commit id>

                – git revert HEAD <commit id>

git reset – The git reset command is a complex and versatile tool for undoing changes.

example – git reset –hard

git rebase – Rebasing is a process to reapply commits on top of another base trip. It is used to apply a sequence of commits from distinct branches into a final commit. It is an alternative of  git merge command. It is a linear process of merging.

example – git rebase <branch name> 

                    git rebase –continue 

                   git rebase –skip 

.gitignore file – The .gitignore file tells Git which files to ignore when committing your project to the GitHub repository. gitignore is located in the root directory of your repo.

create a .gitignore file using “touch .gitignore” command then add a folder which you don’t want to track.


We have been working on this, to know more contact us at info@virasatsolutions.com