Essential git commands every developer should know

There are some lesser-known Git commands that may make your life easier.
We all have our everyday Git commands that we use over and over. But what if I told you there are some lesser-known Git commands that may make your life easier. Let's See!


Photo by Luke Chesser on Unsplash

 # git add-p
   
  We all may know the command git add <file> or git add.But Why do we need to know git add -p 

   Ever wanted to commit just a section of a file and not the entire thing?

Once this command runs, we’ll be asked about "hunks". "Hunks" are the chunks of code that we'll decide what to do with.

You’ll see the question, "Stage this hunk [y, n, g, a, d, e, ?]?" at the bottom of the terminal.

   What Do those letters mean:

  • y: stage this hunk
  • n: do not stage this hunk
  • g: select a different hunk to go to
  • a: stage this hunk and all the other hunks in this file
  • d: do not stage this hunk or any of the other hunks in this file
  • e: edit the current hunk manually
  • ?: print help

 # git commit--amend 

 When committing, sometimes we can hit "Enter" too quickly and have a   typo somewhere in the commit message. 

 For example, we run git commit -m "fixing a typeo" and hit "Enter". Quickly we realize that not only were we trying to fix a typo in the application, but now we need to fix the "typeo" in the commit message.

Running the command git commit —amend -m "fixing a typo" does the trick. Now when we push our commit, our co-workers won’t see that our "typo" was originally spelled "typeo". 

 

 # git reset --soft HEAD~1

 We all know about the command git reset. But what about --soft 

Remove the last commit from the current branch, but keep the changes!

The cool thing about this command is that the changes won’t disappear! All the changes will stay in the working tree!

 

  # git checkout

  This command can help so much when there’s a lot going on in a commit and you would rather not commit the entire thing. we are diving even deeper into a branch and picking just a particular file that we want to be merged. Let’s see!

Pick a specific file from a branch and bring it into the current branch.


 # git cherry-pick

 In this command, we can pick a particular branch that has a commit and pull it into another. 

       Bring an entire commit from one branch into another.


 # git help

There are so many different git commands out there. And before we start running commands without knowing exactly what it’s going to do to our code is important. If we were to run just git help <command> then we would get an explanation of the command right there in our terminal.

got bored of seeing in the terminal?

Running the command git help -w <command> takes us directly to the website that we can read up on all the things with the command in question.


If anything is not clear or you want to point out something, please reach me -- Mail me !.

Comments

Popular posts from this blog

VS Code Extensions For Web Dev Productivity