Commands
Here's a list of commonly used Git commands
🔧 Basic Git Setup
git config --global user.name "Your Name"
git config --global user.email "
[email protected]"
📁 Creating / Cloning a Repository
git init # Initialize a new Git repository
git clone <repo-url> # Clone an existing repository
📄 Working with Files
git status # Show the status of changes
git add <file> # Stage a specific file
git add . # Stage all files
git commit -m "message" # Commit staged changes
git pull --rebase origin dev #(fetch and rebase)
🔄 Branching & Merging
git branch # List all branches
git branch <branch-name> # Create a new branch
git checkout <branch-name> # Switch to a branch
git checkout -b <branch-name> # Create and switch to a new branch
git merge <branch-name> # Merge a branch into the current one
Commands 1
🌍 Remote Repositories
git remote -v # View remote connections
git remote add origin <url> # Add a new remote repo
git push -u origin <branch-name> # Push to remote (first time)
git push # Push committed changes
git pull # Pull changes from remote
🕰️ Viewing History
git log # View commit history
git log --oneline # One-line summary
git show <commit-hash> # Show details of a specific commit
🔁 Undoing Changes
git checkout -- <file> # Discard local changes in a file
git reset HEAD <file> # Unstage a file
git revert <commit-hash> # Undo a specific commit safely
git reset --hard <commit-hash> # Reset to an old commit (dangerous!)
🧹 Clean Up
git clean -f # Remove untracked files
Commands 2