DEV Community

Ahmed Ghoneim
Ahmed Ghoneim

Posted on

Git Starter Pack

We've all probably used git in our companies. Usually we're taught a few basics and then left alone to deal with the monster that is git. Soon we start to have to handle conflicts! This article will help you learn a few tips and tricks to guide you through your development process.

I've changed a file and want it back

There are two situations here:

  • I want it back to the last commit

git checkout <filename>

  • I committed it but I want it back to master

git reset master <filename>

This also works for files you've deleted!

I made a mistake while merging

git merge --abort

I want to select one commit from another branch

git cherry-pick <commit-hash>

I want to remove any files I've changed

git checkout .

I want to remove any new files I've created

git clean -df

I want to look at a certain commit

git checkout <commit-hash>

I want to see the commit history

git log

A couple of conventions

How to write commit messages

  • Use capitalized messages:

Add feature blabla

  • Use verbs in infinitive:

Added Add foobar

How to name branches

  • Use lower-case, url-friendly names

AbCd abcd

a_b a-b

Top comments (0)