Show Menu
Cheatography

Git Commands Basics Cheat Sheet (DRAFT) by

This is a cheat sheet for basic git commads

This is a draft cheat sheet. It is a work in progress and is not finished yet.

Config­uration

git config --global user.name "Your Name"
Set your username globally.
git config --global user.email "­you­r.e­mai­l@e­xam­ple.co­m"
Set your email globally

Starting a Repository

git init
Initialize a new Git repository in the current directory.

Basic Workflow

git status
Check the status of your working directory and staging area
git add <fi­le>
Add a file to the staging area.
git commit -m "­Commit messag­e"
Commit changes with a descri­ptive message
git commit -am "­Commit messag­e"
Add and commit changes in one step (only for modified files, not new files).
git add submodule <li­nk> <Di­rec­tor­y>
Adding a submodule

Branching

git branch
List all local branches
git branch <br­anc­h_n­ame>
Create a new branch
git checkout <br­anc­h_n­ame>
Switch to a different branch
git checkout -b <br­anc­h_n­ame>
Create and switch to a new branch in one step
git merge <br­anc­h_n­ame>
Merge changes from <br­anc­h_n­ame> into the current branch
git branch -d <br­anc­h_n­ame>
Deleting a branch

Remote Reposi­tories

git remote add <na­me> <ur­l>
Add a new remote repository
git remote -v
List all remote reposi­tories
git pull <re­mot­e> <br­anc­h>
Fetch changes from the remote repository and merge them into the current branch
git push <re­mot­e> <br­anc­h>
Push changes from the local repository to the remote

Inspecting Changes

git log
View commit history
git diff
Show changes between commits, commit and working tree, etc
git show <co­mmi­t_h­ash>
Show details of a specific commit

Undoing Changes

git reset HEAD <fi­le>
Unstage a file from the staging area.
git checkout -- <fi­le>
Discard changes in the working directory for a specific file
git reset --hard <co­mmi­t_h­ash>
Reset the repository to a specific commit (WARNING: this is a destru­ctive operat­ion).
 

Miscel­laneous

git clone <re­pos­ito­ry_­url>
Clone a remote repository to your local machine
git pull
Fetch changes from the remote repository and merge them into the current branch
git push
Push changes from the local repository to the remote repository
git submodule update –remote
Updating submodule

Optional tags

-a, --all
Includes all changes (both tracked and untracked files) when executing the command
-m, --message <me­ssa­ge>
Specifies a commit message inline with the command
-b, --branch <br­anc­h_n­ame>
Specifies the branch name when creating a new branch or switching branches
-f, --force
Forces the command to execute, even if it would result in data loss or conflicts
-t, --tags
Pushes tags along with the commits when pushing changes to a remote repository
-u, --set-­ups­tream <up­str­eam>
Sets the upstream branch for the current branch
-v, --verbose
Provides more detailed output, often helpful for debugging or unders­tanding what the command is doing
-p, --patch
Allows for intera­ctive patching of changes (e.g., for selecting specific changes to include in a commit)
-d, --delete
Deletes a branch or tag
-i, --inte­ractive
Runs the command in intera­ctive mode, allowing for user input and intera­ction