Useful Git Commands
Shshank

Shshank @shshank

About: A coding soul

Location:
India
Joined:
May 16, 2018

Useful Git Commands

Publish Date: Jul 14 '22
3 5

Version control (sometimes referred to as source control) plays an important role in any development project, including test automation. It is the practice of tracking and providing control over changes made in the source code. And since one of the most common tools used in version control is Git, let’s get to understand some of the most common Git commands.

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.

  • Initialize current directory as a Git repository.
git init
Enter fullscreen mode Exit fullscreen mode
  • Create a local copy of a repository from a hosted location via URL.
git clone URL
Enter fullscreen mode Exit fullscreen mode
  • Show a list of modified files in your working directory and whether they are staged for the next commit.
git status
Enter fullscreen mode Exit fullscreen mode
  • Add changes from a specific file to the stage, ready for your next commit.
git add file.js
Enter fullscreen mode Exit fullscreen mode
  • Add changes from all files to the stage ready for your next commit.
git add .
Enter fullscreen mode Exit fullscreen mode
  • Unstage a specific file, while still retaining the changes in the working directory.
git reset file.js
Enter fullscreen mode Exit fullscreen mode
  • Unstage all files, while still retaining the changes in the working directory.
git reset
Enter fullscreen mode Exit fullscreen mode
  • Display a list of branches with an asterisk(*) next to the active branch
git branch
Enter fullscreen mode Exit fullscreen mode
  • Create a new branch
git branch name
Enter fullscreen mode Exit fullscreen mode
  • Switch to another branch and check it out into your working directory.
git checkout branch
Enter fullscreen mode Exit fullscreen mode
  • Create a new branch and switch to that branch
git checkout -b branch_name
Enter fullscreen mode Exit fullscreen mode
  • Commit your staged content as a new commit snapshot with a specified message.
git commit -m "your commit message"
Enter fullscreen mode Exit fullscreen mode
  • Fetch all the changes from the remote repository and merge any remote changes in the current local branch.
git pull
Enter fullscreen mode Exit fullscreen mode

These are few basic commands which can help you get started with git easily. Hope you find this article useful.

Thank you.

Comments 5 total

  • dnasedkina
    dnasedkinaJul 14, 2022

    Thanks for compiling this list

  • Paul Knulst
    Paul KnulstJul 14, 2022

    This is a nice list on the basic Git commands.

    I have a nice addition for that. I recently experienced with Git Aliases and have to say that they are really awesome and should be know by every Git user!

    Because I like them so much I created an article that explain how I use them to delete all my local branches that I do not need anymore:

    If you are interested you can read about it here: knulst.de/how-to-remove-local-git-...

    If you did not know about Git Alias it's worth reading about!

    • Shshank
      ShshankJul 14, 2022

      Thanks for sharing, and making this article useful for every reader.

      • Paul Knulst
        Paul KnulstJul 14, 2022

        It already was super useful!!

        I am just so happy about Git Alias and want to spread the information :-D. I'm totally into them since 1 week ^^

        • Shshank
          ShshankJul 14, 2022

          Thanks for sharing great info

Add comment