Skip to main content

Command Palette

Search for a command to run...

Basic Git Commands

Updated
2 min readView as Markdown
Basic Git Commands

What are Git Commands?

Git commands are a distributed version control system for tracking changes in any set of files. They were originally designed for coordinating work among programmers who were operating source codes during software development.

Git is a fast, scalable, and distributed revision control system with an unusually rich command set that provides both high-level operations and full access to internals.

Benefits of Git

  • It’s free (and open-source): You can freely contribute to the code any time and, of course, you don’t need to purchase it, since it is open-source.

  • Performance: It is faster and more reliable than any other version control software as it focuses only on file content rather than on file names.

  • Security: Git protects the code and the change history through a cryptographically secure hashing algorithm, called SHA1.

  • Widely-used: Git has become the preferred VCS tool in many great organizations.

Most Common Git Commands

Using git –help in the command prompt (on Windows), terminal (for Mac), or shell (on Linux) will give you a list of the most important Git commands that will help you to push your work to git.

git init:-

This is the command you need to use if you want to start a new empty repository or to reinitialize an existing one in the project root. It will create a .git directory with its subdirectories. It should look like this:

git init <repository name>

git add:-

This is the command you need to use to stage changed files. You can stage individual files:

git add <file path>

Or all files:

git add .

git commit:-

This one is probably the most used Git command. After changes are done locally, you can save them by “committing” them. A commit is like local a snapshot of the current state of the branch, to which you can always come back. To create a new commit, type this command in Git Bash:

git commit -m "<commit message>"

git push:-

Git push will push the locally committed changes to the remote branch. If the branch is already remotely tracked, simply use it like this (with no parameters):

git push

If the branch is not yet tracked, and only resides on the local machine, you need to run the command like this:

git push --set-upstream <remote branch> <branch name>

Conclusions:-

Git can be a really powerful tool in any development project and you will probably use most of these commands on a daily basis if your team uses Git for version control.