0% found this document useful (0 votes)
13 views2 pages

Git Commands Cheat Sheet

This document is a comprehensive Git command cheat sheet that covers various aspects of Git including configuration, repository management, snapshotting, branching, merging, remote repositories, undoing changes, stashing, viewing history, tags, and advanced commands. Each section provides specific commands along with brief descriptions of their functions. It serves as a quick reference guide for users to efficiently manage their Git repositories.

Uploaded by

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

Git Commands Cheat Sheet

This document is a comprehensive Git command cheat sheet that covers various aspects of Git including configuration, repository management, snapshotting, branching, merging, remote repositories, undoing changes, stashing, viewing history, tags, and advanced commands. Each section provides specific commands along with brief descriptions of their functions. It serves as a quick reference guide for users to efficiently manage their Git repositories.

Uploaded by

saudmd353
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

**Git command cheat sheet**

---

## Configuration & Setup

* `git --version` → Show installed Git version.


* `git config --global [Link] "Name"` → Set your global username.
* `git config --global [Link] "email@[Link]"` → Set your global email.
* `git config --list` → View all Git configurations.

---

## Repository Management

* `git init` → Create a new Git repository in current folder.


* `git clone <repo-url>` → Copy a remote repository locally.

---

## Basic Snapshotting

* `git status` → Show changes (staged, unstaged, untracked).


* `git add <file>` → Stage a file for commit.
* `git add .` → Stage all modified/untracked files.
* `git reset <file>` → Unstage a file (keep changes).
* `git diff` → Show unstaged changes.
* `git diff --staged` → Show staged changes.
* `git commit -m "message"` → Commit staged changes with a message.
* `git commit -am "message"` → Stage and commit all tracked changes.
* `git rm <file>` → Remove file from repo and working directory.
* `git mv <old> <new>` → Rename or move a file.

---

## Branching & Merging

* `git branch` → List all branches.


* `git branch <name>` → Create a new branch.
* `git checkout <branch>` → Switch to another branch.
* `git switch <branch>` → Alternative to checkout for switching.
* `git checkout -b <branch>` → Create and switch to new branch.
* `git merge <branch>` → Merge branch into current branch.
* `git branch -d <branch>` → Delete a branch (safe).

---

## Remote Repositories

* `git fetch` → Download changes without merging.


* `git pull` → Fetch and merge changes from remote.
* `git pull origin <branch>` →
* `git push` → Upload local commits to remote.
* `git push -u origin <branch>` → Push branch and set upstream.
* `git push origin --delete <branch>` → Delete a branch on remote.

---

## Undoing Changes
* `git checkout -- <file>` → Discard local changes in file.
* `git restore <file>` → Restore file (modern alternative).
* `git reset --soft HEAD~1` → Undo last commit (keep changes staged).
* `git reset --mixed HEAD~1` → Undo last commit (keep changes unstaged).
* `git reset --hard HEAD~1` → Undo last commit (discard changes).
* `git revert <commit>` → Create a new commit that undoes given commit.

---

## Stashing (Temporary Save)

* `git stash` → Save changes without committing.


* `git stash pop` → Reapply last stashed changes.
* `git stash list` → Show stashed changes.
* `git stash drop` → Delete a stash.

---

## Viewing History

* `git log` → Show commit history.


* `git log --oneline` → Show compact commit history.
* `git log --graph --oneline --decorate` → Visual branch history.
* `git show <commit>` → Show details of a commit.

---

## Tags & Releases

* `git tag` → List all tags.


* `git tag <name>` → Create a lightweight tag.
* `git tag -a <name> -m "msg"` → Create an annotated tag.
* `git push origin <tag>` → Push a tag to remote.
* `git push origin --tags` → Push all tags.

---

## Advanced

* `git rebase <branch>` → Reapply commits on top of another branch.


* `git cherry-pick <commit>` → Apply a specific commit from another branch.

You might also like