DEV Community

Cover image for Useful Git Commands
Shshank
Shshank

Posted on

Useful Git Commands

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
⚡ Match Highlights: shshank/useful git commands bch - Pertandingan Hari Ini ⚡ Match Highlights: shshank/useful git commands bch - Pertandingan Hari Ini
  • Create a local copy of a repository from a hosted location via URL.
git clone URL
⚡ Match Highlights: shshank/useful git commands bch - Pertandingan Hari Ini ⚡ Match Highlights: shshank/useful git commands bch - Pertandingan Hari Ini
  • Show a list of modified files in your working directory and whether they are staged for the next commit.
git status
⚡ Match Highlights: shshank/useful git commands bch - Pertandingan Hari Ini ⚡ Match Highlights: shshank/useful git commands bch - Pertandingan Hari Ini
  • Add changes from a specific file to the stage, ready for your next commit.
git add file.js
⚡ Match Highlights: shshank/useful git commands bch - Pertandingan Hari Ini ⚡ Match Highlights: shshank/useful git commands bch - Pertandingan Hari Ini
  • Add changes from all files to the stage ready for your next commit.
git add .
⚡ Match Highlights: shshank/useful git commands bch - Pertandingan Hari Ini ⚡ Match Highlights: shshank/useful git commands bch - Pertandingan Hari Ini
  • Unstage a specific file, while still retaining the changes in the working directory.
git reset file.js
⚡ Match Highlights: shshank/useful git commands bch - Pertandingan Hari Ini ⚡ Match Highlights: shshank/useful git commands bch - Pertandingan Hari Ini
  • Unstage all files, while still retaining the changes in the working directory.
git reset
⚡ Match Highlights: shshank/useful git commands bch - Pertandingan Hari Ini ⚡ Match Highlights: shshank/useful git commands bch - Pertandingan Hari Ini
  • Display a list of branches with an asterisk(*) next to the active branch
git branch
⚡ Match Highlights: shshank/useful git commands bch - Pertandingan Hari Ini ⚡ Match Highlights: shshank/useful git commands bch - Pertandingan Hari Ini
  • Create a new branch
git branch name
⚡ Match Highlights: shshank/useful git commands bch - Pertandingan Hari Ini ⚡ Match Highlights: shshank/useful git commands bch - Pertandingan Hari Ini
  • Switch to another branch and check it out into your working directory.
git checkout branch
⚡ Match Highlights: shshank/useful git commands bch - Pertandingan Hari Ini ⚡ Match Highlights: shshank/useful git commands bch - Pertandingan Hari Ini
  • Create a new branch and switch to that branch
git checkout -b branch_name
⚡ Match Highlights: shshank/useful git commands bch - Pertandingan Hari Ini ⚡ Match Highlights: shshank/useful git commands bch - Pertandingan Hari Ini
  • Commit your staged content as a new commit snapshot with a specified message.
git commit -m "your commit message"
⚡ Match Highlights: shshank/useful git commands bch - Pertandingan Hari Ini ⚡ Match Highlights: shshank/useful git commands bch - Pertandingan Hari Ini
  • Fetch all the changes from the remote repository and merge any remote changes in the current local branch.
git pull
⚡ Match Highlights: shshank/useful git commands bch - Pertandingan Hari Ini ⚡ Match Highlights: shshank/useful git commands bch - Pertandingan Hari Ini

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

Thank you.

Top comments (5)

⚡ Match Highlights: shshank/useful git commands bch - Pertandingan Hari Ini
 
paulknulst profile image
Paul Knulst •

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!

⚡ Match Highlights: shshank/useful git commands bch - Pertandingan Hari Ini
 
shshank profile image
Shshank •

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

⚡ Match Highlights: shshank/useful git commands bch - Pertandingan Hari Ini
 
paulknulst profile image
Paul Knulst •

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 ^^

⚡ Match Highlights: shshank/useful git commands bch - Pertandingan Hari Ini Thread
 
shshank profile image
Shshank •

Thanks for sharing great info

⚡ Match Highlights: shshank/useful git commands bch - Pertandingan Hari Ini
 
dnasedkina profile image
dnasedkina •

Thanks for compiling this list