A concise reference forย Gitย commands.
โ๏ธ Configure Git
๐ Global (applies to all repositories)
# Set global name
git config --global user.name "Your Name"
# Set global email
git config --global user.email "your@email.com"
๐ Local (specific to a repository)
# Set local name (for this repo only)
git config --local user.name "Your Name"
# Set local email (for this repo only)
git config --local user.email "your@email.com"
๐๏ธ Initialize & Clone
๐ Initialize a Git repository
git init
๐ฅ Clone a repository
# Clone into a new directory
git clone [url]
# Clone into the current directory
git clone [url] .
# Clone into a specific directory
git clone [url] [path-to-clone]
๐ Stage & Snapshot
๐ Check file status
git status
โ Add files to the staging area
# Stage a specific file
git add [file]
# Stage all files
git add .
โ Remove files from the staging area
# Unstage a specific file
git reset [file]
# Unstage all files
git reset .
๐ Check file changes
# Show unstaged changes
git diff
# Show staged changes
git diff --staged
๐พ Commit changes
# Commit with a message
git commit -m "Commit message"
# Commit with title and description
git commit -m "Commit title" -m "Commit description"
๐ฟ Branching
๐ List branches
git branch
๐ฑ Create a new branch
git branch [branch-name]
๐ Switch to another branch
git checkout [branch-name]
โ๏ธ Rename the current branch
git branch -M [new-branch-name]
๐ View commit history
git log
๐ Share & Update
๐ Remote repositories
# Add a remote
git remote add [alias] [url]
# List remotes
git remote -v
# Show details of a remote
git remote show [alias]
# Get the URL of a remote
git remote get-url [alias]
# Remove a remote
git remote remove [alias]
๐ค Fetching & pushing
# Fetch and merge changes from remote
git pull
# Push and set upstream for the first time
git push -u [alias] [branch]
# Push to a specific remote and branch
git push [alias] [branch]
# Push to the default remote/branch
git push
๐ซ Ignoring Files
Create aย .gitignoreย file to exclude files/folders from being tracked:
logs/
*.notes
pattern*/
Top comments (0)