Git Cheat Sheet

WojciechWojciech
1 min read

This cheat sheet summarizes my most commonly used git commands, and I will update it periodically.

Initialize

git config --global user.name "Name Username"
git config --global user.email name@example.com

I rarely initialize a repo locally, so I don't need to use git init. However, keep in mind that it's useful for initializing an existing directory as a Git repository.

Basic commands

git checkout -b <new-branch> # create new branch and switch to it, never work directly on master
git add . # add all files to next commit (stage them)
git status # check files added to commit
git commit -m "commit msg" # commit files to branch
git push # push changes to remote repository
git pull # pull changes pushhd to remote repository

Advanced commands

git revert <commit> # creates NEW commit that reverts changes introduced in specified commit
git rebase <branch> # reapplies commits on the current branch onto the tip of the specified branch
0
Subscribe to my newsletter

Read articles from Wojciech directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Wojciech
Wojciech

DevOps Engineer specializing in System Engineering and Administration, committed to continual learning and technical growth. I actively build and manage a personal homelab, and I am driven to explore new challenges and emerging technologies.