/ 33浏览

Git cheatsheet

81e5fbba2ecf028b0894bb87c0928773-20240903114032-cgvyuxe

Git is a decentralized version management software. With this cheatsheet you will have a quick access to the most common git commands.

Configuration

Set the global config

git config --global user.name "[name]"
git config --global user.email "[email]"

Get started

Create a git repository

git init

Clone an existing git repository

git clone [url]

Commit

Commit all tracked changes

git commit -am "[commit message]"

Add new modifications to the last commit

git commit --amend --no-edit

I’ve made a mistake

Change last commit message

git commit --amend

Undo most recent commit and keep changes

git reset HEAD~1

Undo the N​ most recent commit and keep changes

git reset HEAD~N

Undo most recent commit and get rid of changes

git reset HEAD~1 --hard

Reset branch to remote state

git fetch origin
git reset --hard origin/[branch-name]

Miscellaneous

Renaming the local master branch to main

git branch -m master main