DEV Community

Cover image for A Useful Git Command
James 'Dante' Midzi
James 'Dante' Midzi

Posted on • Originally published at dantedecodes.hashnode.dev

A Useful Git Command

As a developer version control is something that is most likely in your wokflow. If not, you should really consider taking the time to incorporate it.

The most common git commands are

  • git init - initialise an empty git repository
  • git add - adds file(s) to staging area
  • git commit - to save your changes to source control
  • git push - to push changes to a remote repository
  • git log - to show a record of what has happened on the repository
  • git status - to see the status of things in your version flow: new, unstaged, uncommited etc

But there is one more command, that no one told you about, one that is a game changer.

Enter git add -p

In most instance when you make changes to your file, you use git add to stage those files and then git commit -m to save them to source control.

Let's what happens with git add -p:

commis.png

From the screenshot above:

  • I modified the commissions page slightly
  • In my terminal I ran the command git add -p
  • This showed me everything that's been changed and a prompt to stage those changes

If I had made more changes, It would show me the changes one by one and ask me whether I want to stage them or not

morecomm.png

After staging your changes, all that's left is to commit them.

Conclusion

I am sure you can see how useful this could be to keep proper track of the changes you make during your development flow and decide what to stage or not.

Much better than going git add [filename], no?

I write this article partially because whitep4nth3r was on the fence about writing about it.


Thank you for reading, let's connect!

Thank you for visiting this little corner of mine. Let's connect on Twitter, Polywork and LinkedIn

Top comments (0)