burme-coder-max / data /knowledge /skills /git_skills.md
amkyawdev's picture
Upload folder using huggingface_hub
a7d7463 verified
|
Raw
History Blame Contribute Delete
4.12 kB

Git Skills

Setup & Config

# Configure user
git config --global user.name "Your Name"
git config --global user.email "your@email.com"

# Configure editor
git config --global core.editor vim

# List config
git config --list

Basic Commands

Status & Logs

git status              # Show working tree status
git status -s          # Short format
git log                # Show commit history
git log --oneline      # Compact log
git log -n 5           # Last 5 commits
git log --graph        # Visual branch graph

Add & Commit

git add file.txt              # Stage single file
git add .                     # Stage all changes
git add -p                   # Interactive staging
git commit -m "message"      # Commit with message
git commit -am "message"     # Add + commit (tracked files)
git commit --amend           # Modify last commit

Branching

git branch                    # List branches
git branch feature/login      # Create branch
git checkout feature/login    # Switch to branch
git switch -c feature/login   # Create and switch (modern)
git branch -d feature/login  # Delete branch
git branch -m new-name       # Rename current branch

Merging

git checkout main
git merge feature/login       # Merge feature into main
git merge --no-ff feature    # No fast-forward merge
git merge --squash feature   # Squash commits

Rebasing

git rebase main              # Rebase onto main
git rebase -i HEAD~3         # Interactive rebase
git rebase --continue
git rebase --abort

Remote Operations

Push & Pull

git push origin main         # Push to remote
git push -u origin feature   # Push with upstream
git push --force             # Force push (use carefully)
git pull                    # Pull and merge
git pull --rebase           # Pull with rebase
git fetch                   # Fetch without merge

Remote Management

git remote -v               # List remotes
git remote add origin url    # Add remote
git remote remove origin    # Remove remote
git remote rename origin upstream

Advanced Operations

Stashing

git stash                   # Stash changes
git stash pop              # Apply and remove stash
git stash apply            # Apply without removing
git stash list             # List stashes
git stash drop             # Delete stash
git stash -u               # Include untracked files

Resetting

git reset HEAD~1           # Reset to commit before last
git reset --soft HEAD~1    # Keep changes staged
git reset --hard HEAD~1    # Discard all changes

Cherry Picking

git cherry-pick abc123      # Cherry-pick single commit
git cherry-pick abc123 def456  # Multiple commits

Tagging

git tag v1.0.0             # Create tag
git tag -a v1.0.0 -m "Release 1.0"  # Annotated tag
git push origin v1.0.0     # Push tag
git tag -d v1.0.0           # Delete local tag

Workflow Examples

Feature Branch Workflow

git checkout -b feature/new-feature
# Make changes
git add .
git commit -m "Add new feature"
git push -u origin feature/new-feature
# Create PR on GitHub/GitLab
# After PR merged
git checkout main
git pull origin main
git branch -d feature/new-feature

Hotfix Workflow

git checkout main
git pull
git checkout -b hotfix/bug-fix
# Fix the bug
git commit -am "Fix critical bug"
git checkout main
git merge --no-ff hotfix/bug-fix
git push origin main
git branch -d hotfix/bug-fix

Finding & Fixing Issues

Blame & Show

git blame file.txt         # Show who changed what
git show abc123            # Show commit details
git show abc123:file.txt   # Show file at commit

Bisect (Find Bug)

git bisect start
git bisect bad HEAD
git bisect good abc123
# Test...
git bisect good  # or git bisect bad
git bisect reset

Diff

git diff                    # Unstaged changes
git diff --staged          # Staged changes
git diff HEAD~1            # vs previous commit
git diff main...feature    # Changes in feature branch