7 git commands that I use every day as a Software Engineer.

A Aditya
4 min readNov 5, 2022

--

Before we jump right into the commands, let me give a brief information about git. For those who are already familiar with Git can skip to the 3rd subtopic.

Git is the most magical invention that has ever touched the developer world. It has changed the Tech industry tremendously.

It is a version control system or in game terms it helps you save your progress of your game. But it is much more powerful in the terms that you can jump to any saved version of your code and make changes to it. It provides a safe and risk-free environment for new developers. As new developers are bound to make many mistakes, the can rest assure that even if they create a major issue while coding, we can just get back to the version of the code which was running fine.

Git was developed in 2005 by Linus Torvalds to be used by developers involved in the development of the Linux Kernel.

Why do you need git?

Git helps by:

  • Create multiple copies of a project, so that developers can work on it separately without affecting the main project.
  • Let all developers know of the changes made to the main code
  • Helps in communication between developers.
  • Provides a environment where any code can be added and erased at any point in time.

Git has now become an essential tool in managing projects. One cannot imagine working on big projects without Git. It makes developing easy and risk free as the developer need to worry about their mistakes bringing the whole project down.

Before using the commands mentioned in this article, please follow the following links to get your Git up and running

Git Installation

Join GitHub(either GitHub or GitLab is fine)

Join GitLab(either GitHub or GitLab is fine)

Step by Step guide to start using Git.

- git checkout

Git checkout command is used to either switch branch on which you want to work, or to create a new branch and push all your worked codes.

I personally use it mainly to jump between different copies of a project. But switching between multiple features of an app can also be the case.

  • To jump to another branch : git checkout {branch name}
  • To create a new branch: git checkout -b {branch name}

- git pull

Git pull is used to get changes from a remote repository to your current branch. I generally use git pull after switching to a new branch . I also use this command once before I start working on a new task for the project.

  • to pull code from repo use : git pull

- git commit

The git commit command is one of the primary funstions of git. Before committing one must first stage the changes that you want to send in the next commit. So git commit is used to save changes to the code and acts as a save point.

A commit id is also generated with each commit. The commit ID is a cryptographic number created by SHA(Secure Hash Algorithm).

to commit your code use: git commit -m “commit message”

- git revert

Git revert is used to undoing changes. If yoiu have commit some code that you did not wish you can use this command. In simple terms it is deleting your changes but not really, it actually creates a new commit that does not have your changes. I use this command along with the commit ID.

to revert commits use: git revert {commit ID}

- git push

git push is the commands which is used to upload local repository content to remote repository.

There are 2 major variations of push that use most of the time.

To push all your commits into the remote repo use: git push — set-upstream origin {branch name}

to force push: git push -f (generally not recommended)

- git cherry pick

Git cherry pick is used to select individual commit using their commit ID and use and integrate it into your current branch.

It is a very convenient command.

to use cherry pick: git cherry-pick {commit ID}

- git log

Git log is a review tool with which you can see all the commits made to the HEAD branch. Mutiple options can be used to make the history more specific.

To use: git log

This completes the list of 7 git commands that I use as a entry level software developer. Apart from these there are quite a few commands that can be used. These are the ones that are essential and will help you get started in your development journey. This is also really helpful if you're starting out with open source.

To know more about git checkout out the official documentation

Git Docs

Hope you learnt a little about Git. Let me know what you think about this article. If you like reading my content, consider giving me a follow!

--

--

A Aditya

Just a random guy sharing his experience and knowledge about Technology and FInance.