Post

Git Cheatsheet

Git

Git Commands

SET UP & INITIALIZATION

Check for version

1
git --version

Configure your username

1
git config --global user.name “firstname lastname”

Configure your email

1
git config --global user.email “your-email”

Initialize your current working directory as a Git repository

1
git init

Show your current Git directory’s remote repository

1
git remote

STAGING

Check the status of your Git repository

1
git status

To add a specific file

1
git add <file-name>

To add all files in the current working directory

1
git add .

To add all files in the current working directory as well as files in subdirectories

1
git add -A

To remove a file from staging while retaining changes within your working directory

1
git reset <file-name>

COMMITING

I follow the Conventional Commits style to write my commit messages. To know more about this style, check here

To commit staged files

1
git commit -m "Commit message"

To commit all staged files in one step

1
git commit -am "Commit message"

To modify your commit message

1
git commit --amend -m "New commit message"

BRANCHES

To list all current branches

1
git branch

To create a new branch

1
git branch <branch-name>

To switch to any existing branch and check it out into your current working directory

1
git checkout <branch-name>

To consolidate the creation and checkout of a new branch

1
git checkout -b <branch-name>

To rename your branch

1
git branch -m <current-branch-name> <new-branch-name>

To merge a specified branch’s history into the one you’re currently working in

1
git merge <branch-name>

To abort the merge, in case there are conflicts

1
git merge --abort

To delete a merged branch

1
git branch -d <branch-name>

To delete a branch that has not been merged

1
git branch -D <branch-name>

To delete a remote branch

1
git push <remote-name> --delete <branch-name>

STASHING

Stash your current work

1
git stash

To list your stashed work

1
git stash list

To bring files out of a stash

1
git stash pop

To remove multiple stashes

1
git stash clear
This post is licensed under CC BY 4.0 by the author.