Version Control system and Git commands

Sithara Rao
4 min readJul 14, 2020

This post will give you an overview of VCS, types of VCS, and the git commands that we usually use in our day-to-day life.

Let us understand what is VCS and its uses

Version Control System (VCS) is a configuration system that is responsible for the management of changes related to documents, code and other collections of information. It maintains a revision history for all the changes. There are two types in it.

  1. Centralized VCS
  2. Distributed VCS

In Centralized VCS, the developers need to connect to one centralized system where all the commits and pushes are made. If there is any issue with one of the code commits, then it affects the entire group who are working on the code base as each individual works on one major system.

Example: SVN, CVS

Centralized VCS
Centralized VCS affecting all the developers due to random developer’s commit

In Distributed VCS, every developers will have the remote code base in their local system. The changes are locally reflected and when the code is committed, peer review is done and the properly working code gets merged into the remote repository.

Example: Git, Mercurial

Distributed VCS
Code merge in Distributed VCS

Git:

The Wikipedia definition of Git is a distributed version-control system for tracking changes in source code during software development. It is designed for coordinating work among programmers, but it can be used to track changes in any set of files. Its goals include speed, data integrity, and support for distributed, non-linear workflows

It was developed by Linus Torvalds in the year 2005. He described Git as “the stupid content tracker” with a random three-letter combination that is pronounceable, and not actually used by any common UNIX command.

Following are few of the Git commands that are mostly used:

  1. git status: To know the status of the code files
  2. git pull: To pull the updated code from the remote repository
  3. git stash: Stashes the tracked files in a temporary stack
  4. git stash -- include-untracked: Stashes the tracked and untracked files [new files created by us]
  5. git stash pop: This command gets back the stashed changes to the working directory
  6. git add <file_name>: To add the files that are going to be committed. Many files can be added at once separated by space [Ex: git add xyz.java abc.java]. If the entire src files that are changed needs to be pushed, we can do git add app/src/. ]
  7. git reset <file_name>: It removes the file that is added to the commit
  8. git checkout <file_name>: This command reverts all the changes made locally to whatever was present in the remote
  9. git checkout <branch_name>: Used when we want to switch to an other branch of the same project
  10. git commit -m “commit_message”: Adds the message for the commit
  11. git commit --amend: This should be done during patch-set only [Committing new changes to the already pushed code that is not merged]. We have to add the modified files, then the above command has to be executed to include the changes to the applied commit. It simply refers to editing the already committed code
  12. git push: This pushes the code to the remote repository
  13. git reset --hard HEAD~<ahead_by_x_commits_number>: This is used to reset all the commits made and clears the working tree
  14. git reset --soft HEAD~<ahead_by_x_commits_number>: It will get back the commits of the specified X factor number provided. This can be done if the code gets abandoned and all the changes that were done are needed back in the local repository. This will not alter the index of working directory
  15. git clean -f -d: Used to remove untracked files and directories present in the working tree.This command will remove all the untracked files. If we need to remove one of the untracked files, then use rm <file_name>
  16. git --help: 😉And the most valuable command for understanding the commands present in the git. Also to master the git commands in depth, we can use git help <command_name>

Hope this post made you understand the overview of VCS and Git. Stay tuned for updates! 🙋🏻

--

--