Skip to content

Instantly share code, notes, and snippets.

@phirebase
Last active June 22, 2025 14:49
Show Gist options
  • Save phirebase/68fc05c24c300f4a5946f1c5ae450976 to your computer and use it in GitHub Desktop.
Save phirebase/68fc05c24c300f4a5946f1c5ae450976 to your computer and use it in GitHub Desktop.
Git Quick Commands

Git Quick Commands

A collection of essential Git commands for managing your code repositories efficiently.

1️⃣ Git Configuration

Check current configuration:

git config --list

Set username and email:

git config --global user.name "Your Name"
git config --global user.email "[email protected]"

2️⃣ Repository Management

Initialize a new repository:

git init

Clone an existing repository:

git clone [repository-url]

Check current status:

git status

3️⃣ Working with Changes

Stage changes:

git add [file]

Stage all changes:

git add .

Commit changes:

git commit -m "Your commit message"

Unstage a file:

git reset [file]

4️⃣ Branching

List branches:

git branch

Create a new branch:

git checkout -b [branch-name]

Switch branches:

git checkout [branch-name]

Delete a branch:

git branch -d [branch-name]

5️⃣ Merging and Rebasing

Merge a branch:

git merge [branch-name]

Rebase current branch:

git rebase [branch-name]

6️⃣ Remote Repositories

Add a remote repository:

git remote add origin [url]

Push changes to remote:

git push origin [branch-name]

Pull latest changes:

git pull origin [branch-name]

7️⃣ Undo and Recovery

Discard local changes:

git checkout -- [file]

Revert a commit:

git revert [commit-id]

Reset to a previous commit:

git reset --hard [commit-id]

8️⃣ Logs and History

View commit history:

git log

View a summarized log:

git log --oneline

Show changes for a file:

git diff [file]

📚 Official Git Documentation
For more in-depth information, visit: https://git-scm.com/doc

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment