Speed run: learn Git essentials in 15 min


Learning Git can be frustrating. Allow me to quickly introduce you to some of the most useful commands. At the end, I've included articles to read if you want to dive deeper.

git init

Initiates a Git repository, meaning that after you run this command, Git will be able to "see" all files in the current folder. It is particularly useful when you are creating a project from scratch. It may be unnecessary to run this command if you are creating a new project using templates (e.g., running commands like npx create-…)

git add <filename.extension>

First command to write for your first ever Git contribution. It is like adding things to the box that you are going to pack later.

Git add command is like adding things to the box that you are going to pack later

git commit -m “<your commit message>”

This command is like closing that box, sealing it, and putting a label on it.

Git commit command is like closing the box and putting a label on it

git push origin main

This command will send your box to fly into the unknown. Just joking, it will launch your box to the remote repository, somewhere on the server, where your work will be safely stored. Later, you will be able to access your changes even from another device.

Git push command is like sending your box to the remote repository, where it will be stored safely

git pull

This command will bring the latest changes from the remote repository to your local machine. It is like tugging on a rope that leads to a surprise box-rain. The boxes that were sent by your fellow coders will fall on your head.

Git pull command is like tugging on a rope, that leads to a surprise box-rain. The boxes that were sent by your fellow coders will fall on your head.

git checkout -b fix/flying-box

Will create a new branch with the name "fix/flying-box" and switch you to that branch. Read more about common rules on how to name branches appropriately in [Conventional Branch]

Imagine that you want to try implementing a feature, but you don't want to destroy the current state of the project, which is working perfectly. Creating a new branch before trying out new code is a perfect strategy.

Create a new branch with git checkout -b command and put yourself in that branch

git checkout main

Will switch you back to the main branch. Substitute "main" with any other existing branch name, and you will magically teleport there.

Forgot which branches you created? Then run

git branch

Will list all locally available branches.

git cherry-pick <commit-hash>

Created a great commit but forgot that you're on the wrong branch? No panic. Checkout to the correct branch and run this command. It will copy the changes to your current branch. You can delete the other commit now. Don't know what the commit hash is? The next command will help.

git log

This command will list the latest commits from the current branch you are sitting on. The bunch of numbers in the beginning is a commit hash. To escape this view, press 'q'.

Git log command will list the latest commits from the current branch you are sitting on.

git status

Got lost? This command allows you to understand where you currently are and whether you have any changes “added to the box” = “staged”

Git status command will show you where you currently are and whether you have any changes staged

git merge <feature-branch-name>

Finished your awesome feature, tested it, and now you want to add it to the main project branch? If you are working without MRs (merge requests) or PRs (pull requests), then just checkout to main and use this command.

git rebase main

Do you want to see the latest changes from the main in your feature branch? This command will move the origin of your branch from the commit in the past, to the latest commit on main.


If you want to learn more in an interactive way, go to Learn Git Branching

There is also an awesome article by Neil Kakkar, where he dives a little bit deeper and also keeps it fun: How not to be afraid of GIT anymore