Skip to content

Instantly share code, notes, and snippets.

@sketchpunk
Last active July 7, 2026 02:31
Show Gist options
  • Select an option

  • Save sketchpunk/00db87352fe3fb568095a45b7aa88cc5 to your computer and use it in GitHub Desktop.

Select an option

Save sketchpunk/00db87352fe3fb568095a45b7aa88cc5 to your computer and use it in GitHub Desktop.
GIT Cheat Sheet

GIT

BRANCHES

Get List
git branch --list

Delete Local Branch git branch -d feature-xyz

Local & Remote List
git branch -a

Remote List
git branch -r

Local branches in relation to remote status
NOTE: Tell how many commits behind or if branch has been del on remote with gone status. git branch -vv

Checked Out
git branch --show-current

Get state of branch
git status

List out last few commit messages & IDs
git log main --oneline

Pull down repo data
git fetch

Removes local references to remote branches but does not remove local branch
git fetch --all --prune or
git remote prune origin

Update repo for fast-forward only, stops if there are conflicts
git pull --ff-only

Create branch from current checked out branch with modified code
git switch -c {NEW_BRANCH_NAME}
or
git checkout -b {NEW_BRANCH_NAME}

Push local branch up & create link
git push -u origin {NEW_BRANCH_NAME}

CONFIG

git config --global user.email "@gmail.com" git config --global user.name ""

COMMITS

Change the message of the most recent commit
git commit --amend -m "Camera List Panel & Free Camera"

Publish a brand-new local branch to a remote repo
git push -u origin {your-branch-name}

Safely overwrites the remote with your local commit history, only if no one else has pushed to branch
git push origin {your-branch-name} --force-with-lease

REBASE

git pull --rebase origin main

STASH

Stash changes included untracked files
git stash -u

Stash everything and include a message
git stash push -u -m "Message"

List all stash items
git stash list

Applies recent stash item AND removes it from stash
git stash pop

Applies recent stash item BUT does not remove from stash
git stash apply

Apply a specific stash item
git stash apply stash@{0}

Delete all stashes
git stash clear

Extract file out of stash
git show stash@{0}:path/to/file.ext > path/to/file_stashed.ext

CONFLICTS

Resolve file conflicts BUT it adds it to staging too
git add {FILE_PATH}

Move stagged file back to changes, helpful after resolving conflict with add
git restore --staged {FILE_PATH}

SUB MODULES

Add Repo
git submodule add {GIT_URL} {LOCAL_FOLDER}

Add Repo & Checkout Branch
git submodule add -b {BRANCH_NAME} {GIT_URL} {LOCAL_FOLDER}

Ignore the pinned version, download latest code in submodules
git submodule update --remote --merge

Submodule is empty or a new one added to root project
git submodule update --init --recursive

Pull root project and sub modules
git pull --recurse-submodules

PROCESS

From scratch sub module repo with web server

# ~~~~~~~~~~~~~~~~~~~~~~~~
# Create root folder
mkdir layouts
cd layouts

# ~~~~~~~~~~~~~~~~~~~~~~~~
# Init git
git init

# ~~~~~~~~~~~~~~~~~~~~~~~~
# clone & add as module
git submodule add https://github.com/c.git core

git submodule add https://github.com/z.git "asd"

# ~~~~~~~~~~~~~~~~~~~~~~~~
# clone, add as module & checkout dev branch
git submodule add -b development https://github.com/xxx.git yyy

# ~~~~~~~~~~~~~~~~~~~~~~~~
# setup web server
npm init -y
npm install -g browser-sync

# add server config: bs-config.js

# Add to Project Scripts:
# "dev": "browser-sync start --config bs-config.js"

# Run Server
npm run dev

TROUBLE SHOOTING

Can not run NPM in VS Code

The problem is powershell & policies blocks it from running script. A quick workaround is to switch to CMD as the default terminal.

- In VS Code, press Ctrl + Shift + P
- Type "Terminal: Select Default Profile"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment