[go: up one dir, main page]

0% found this document useful (0 votes)
9 views4 pages

Git Command Cheat Sheet

This document is a comprehensive Git command cheat sheet that covers various aspects of using Git, including configuration, repository setup, staging, committing changes, branching, merging, fetching, pushing, and more. It provides essential commands for managing repositories, handling branches, and performing common workflows. Additionally, it includes commands for undoing changes, stashing, and working with submodules.

Uploaded by

Vaibhav Bhosale
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views4 pages

Git Command Cheat Sheet

This document is a comprehensive Git command cheat sheet that covers various aspects of using Git, including configuration, repository setup, staging, committing changes, branching, merging, fetching, pushing, and more. It provides essential commands for managing repositories, handling branches, and performing common workflows. Additionally, it includes commands for undoing changes, stashing, and working with submodules.

Uploaded by

Vaibhav Bhosale
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Git Command Cheat Sheet

Configuration

-------------

git config --global user.name "Your Name"

git config --global user.email "you@example.com"

git config --list

Repository Setup

----------------

git init

git clone <repo-url>

Staging & Snapshots

-------------------

git status

git add <file>

git add .

git reset <file>

Commit Changes

--------------

git commit -m "Your message"

git commit -am "Commit + add"

Branching

---------

git branch

git branch <name>

git checkout <name>

git checkout -b <name>

git switch <name>

git switch -c <name>


git branch -d <name>

Merging & Rebasing

------------------

git merge <branch>

git rebase <branch>

Fetching & Pulling

------------------

git fetch

git pull

git pull origin <branch>

git pull --rebase origin <branch>

Pushing

-------

git push

git push origin <branch>

git push -u origin <branch>

git push origin --delete <branch>

History & Logs

--------------

git log

git log --oneline --graph --all

git show <commit>

Undo & Revert

-------------

git restore <file>

git checkout -- <file>

git reset HEAD~1

git revert <commit>


Diff & Compare

--------------

git diff

git diff --staged

git diff <branch1>..<branch2>

Remote Repos

------------

git remote -v

git remote add origin <url>

git remote remove origin

Stashing

--------

git stash

git stash pop

git stash apply

git stash list

Submodules

----------

git submodule add <repo> <path>

git submodule update --init --recursive

Advanced / Cleanup

------------------

git cherry-pick <commit>

git reflog

git clean -fd

Publishing New Repo to GitHub

-----------------------------
git init

git add .

git commit -m "Initial commit"

git branch -M main

git remote add origin <repo-url>

git push -u origin main

Common Git Workflows

--------------------

# Create & Push New Branch

git checkout -b feature/login

git push -u origin feature/login

# Sync with Main

git checkout main

git pull origin main

git merge feature/login

# Delete Branch After Merge

git branch -d feature/login

git push origin --delete feature/login

You might also like