Git Commands

By | October 12, 2021
Git Commands

While working on a big project with a developer team, we use a version control system (VCS) that keeps track of the project code and maintains all the versions of it, so even if we want to roll back to the previous version, we would do that easily. Git is the most popular, fast, and scalable version control system, and it works on commands. Here in this article, we have provided some of the most important Git commands that you should know if you want to use Git for version control.

If we do not use a version control system, we will not be able to manage project versions properly. For example, if we create a new project that contains a lot of files and after a week we want to add some new functionality, we would add some new code or edit some code in the previous file and create a new version of that project.

Vamware

This all process of changing or modifying the previous version of projects can be tracked by a version control system like Git so other developers that are working on the same project can see what changes have been made on the project and what was the previous code.

Please note that here we have not covered all the commands of Git because there are hundreds of Git commands, and it is impossible to go through each one and learn them. Thus, we focus only on the essential Git commands here that are enough to serve our purpose.

What is Git?

Git is an open-source, Distributed Version Control System (DVCS). It is an application that keeps track of your project version and helps you to manage the project. Being a distributed VCS means that all the members of a team that are working on the same project would have the complete version of the project.

Git Features

  • Keeps track of project files.
  • Tracks all the changes made in the project.
  • Records all the changes.
  • It can restore an old version of the project.
  • Helps to compare the new code and old code.
  • Distributes the same project to different developers.
  • Merges code from a different computer.

Git Commands

Here we are sharing a curated list of Git Commands that are executed by the developers on a day-to-day basis:

Git Command Description
git add Adds all the new files to the initialize repository.
git archive Creates a zip or tar file of the content from your repository.
git branch This command prints all the branches linked to that repository.
git branch branch_name Adds a new branch to the repository with the name branch_name.
git checkout With this command, we can switch from one branch to another branch.
git clone

example:

git clone [urls]

Using this command, you can clone an existing repository or directory to your system.
git commit –m “message” The commit command records the file in the previous version.
git config

example:

git config –global user.name “Username”

git config –global user.email “useremail@”

This command is used to set the author’s username and email address when the commit is done.
git diff The diff command is used to show the difference of the files that are not staged.
git fetch [url] Downloads an object from another repository.
git –help Prints the most commonly used commands.
git init

example:

git init [directory name]

This command is used to initialize a new directory or repository to the git.
git log Prints the entire version history.
git merge This command can be used to merge any branch with the current branch.
git mv filename Moves or renames any file, directory, or a symlink.
git pull repository_url This command works the opposite of the push command. With this Git command, you can bring the changes to your local repository if anyone has made changes to the remote repository.
git push

example:

git push origin master

With the push command, we can push or commit changes in the master branch that will reflect on your remote repository.
git remote Connects your repository with the remoter server.
git reset Works opposite of the commit command and thus, undoes the commit statements.
git rm filename rm stands for removal, and this command is used to remove a specific file from the repository.
git show This command is used to show all the objects of the directory. It simply shows all the present code.
git status Lists all the files that have been committed.
git tag commit_ID With the tag command, we can tag some specific commits.
git –version Shows the git suite version.
git-add Adds a net content to the index.

Summary

There are hundreds of git commands, but here, we have provided only a few of them. If you use Git for your project, then these are the most common Git commands you will use frequently. When you use Git, you do not need to learn each command. Just learn the basic ones, and those are enough to serve your purpose. The most common git commands are:

To set a repository:

  • init
  • clone

To make changes to the files:

  • add
  • mv
  • reset
  • rm

To check the history:

  • bisect
  • grep
  • log
  • show
  • status

To grow and mark the changes or history:

  • branch
  • checkout
  • commit
  • diff
  • merge
  • tag

To work in collaboration:

  • push
  • pull
  • fetch

Ensure adding git before each of these Git commands.

People are also reading:

One thought on “Git Commands

Leave a Reply

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