Git Commands Every Developer Should Know

When we start our journey of Development, we come across many different software and terms. One of the most common term we hear is GIT. So what is this Git?

Git is the most commonly used version control system. It basically tracks all our changes which we make into our code files while developing a Project. Git is a very helpful and powerful tool in the world of development. Every developer be it a Web developer or a mobile developer has to learn about git and its uses.

Git basically helps us to keep a record of all the things which we have done along with all the changes, additions or deletions which we have made in our files. It basically marks checkpoints so in case if we make a blunder later in our code base, we can simply revert back to a previous stable stage. It also makes collaboration among various team members easier as all the members can contribute to the same code base at the same time.

So in this article I will show you some of the most commonly used Git commands which we use while developing the applications.

Git init

This is the first command which we run when we create a new project to initialize a new Git Repository inside the folder. It can also be used to convert an existing unversioned project to a git repository. All the commands are used after git init has initialized an empty repo.

Usage:

git init

Git add

After creating, modifying or deleting a file, we need to include the changes of a file(s) so that they get reflected in the next commit. So for this purpose we use Git add. So basically when we do any operation on the files, these changes just happen in our local system and are not included in the next commit.

To add a single file:

git add <file>

To add everything at once:

git add .

Git commit

This command is the most used command of Git. This is used when we want to save specific changes in our development cycle. It is basically a small checkpoint which we create while developing applications. These checkpoints can be visited later as well. This is done after git add command.

Usage:

git commit -m "commit message"

Git status

This command provides us all the important information about a current branch. It displays information about unstaged, staged and untracked files. It also displays information about the creation, modification or deletion of the files. Along with this it also tells about whether there is anything to commit, push or pull.

Usage:

git status

Git branch

While using Git, branches play an important role. It is the branches which enable several developers to work parallel on the same project. Branches are also helpful while implementing new features in the application.

Create a new Branch:

git branch <branch-name>

Viewing branches:

git branchorgit branch --list

Deleting a branch:

git branch -d <branch-name>

Git checkout

This command is used to switch to a particular branch on which you want to work on. After a new branch is created, this switching is very important.

Usage:

git checkout -b <branch-name>

Git push

Now after we have committed our changes in our local machine, we also need to send those changes to the remote repository which can be on GitHub, GitLab etc. To do this we use the push command in git. It uploads all our commits to the remote repository.

Usage:

git push -u origin <branch-name>

Git pull

This command basically fetches all the updates and changes from a remote repository. So this basically fetches the changes and then merges those with our local repo.

Usage:

git pull <remote>

Git clone

This command is used for getting all the files and existing source code from a remote repository. When we do git clone of any repository then, it makes an identical copy of the project which we have cloned in our local system.

Usage:

git clone <repo-url>

So here were some of the Git command along with their uses. You can explore more about Git HERE.

If you had takeaways from this article then do hit a 👍 button.

Once again Thanks a Lot for Reading this Article😃