Skip to content

Latest commit

 

History

History
174 lines (157 loc) · 3.91 KB

File metadata and controls

174 lines (157 loc) · 3.91 KB

Git Usage Guide: Comprehensive Documentation

Based on our discussions about Git, branches, versioning, and troubleshooting


Table of Contents

  1. Basic Git Commands
  2. Branch Management
  3. Version Control & Tags
  4. Reverting to Previous Versions
  5. Pushing & Pulling Changes
  6. Troubleshooting
  7. Picom & Kvantum Fixes (Bonus)

1. Basic Git Commands

Initialize a Repository

git init

Clone a Repository

git clone <repository-url>

Check Status

git status

Stage Changes

git add <file>       # Add specific file
git add .            # Add all changes

Commit Changes

git commit -m "Your commit message"

View Commit History

git log --oneline    # Compact view
git log -p           # Detailed changes

2. Branch Management

List Branches

git branch           # Local branches
git branch -a        # All branches (local + remote)

Create & Switch to a New Branch

git checkout -b <branch-name>      # Old syntax
git switch -c <branch-name>        # New (Git ≥ 2.23)

Switch to an Existing Branch

git checkout <branch-name>
git switch <branch-name>

Delete a Branch

git branch -d <branch-name>        # Safe delete (checks merges)
git branch -D <branch-name>        # Force delete (unmerged changes)

Push a Branch to Remote

git push -u origin <branch-name>   # First push (sets upstream)
git push                           # Subsequent pushes

3. Version Control & Tags

List Tags

git tag -l

Create a Tag

git tag v1.0.0 -m "Release version 1.0.0"

Push Tags to Remote

git push origin --tags

Checkout a Tag (Read-Only)

git checkout v1.0.0

Create a Branch from a Tag

git checkout -b <new-branch> v1.0.0

4. Reverting to Previous Versions

Find Old Commits

git log --oneline    # Copy the commit hash (e.g., `a1b2c3d`)

Revert to a Specific Commit

Method 1: Soft Reset (Keeps Changes)

git reset --soft a1b2c3d

Method 2: Hard Reset (Discards Changes)

git reset --hard a1b2c3d   # ⚠️ Destructive! Use carefully.

Method 3: Revert (Safe for Shared Branches)

git revert a1b2c3d         # Creates a new undo commit

Rollback to a Tag

git checkout -b rollback-branch v0.7.1

5. Pushing & Pulling Changes

Push Changes to Remote

git push origin <branch-name>

Force Push (Overwrites Remote History)

git push --force origin <branch-name>   # ⚠️ Use with caution!

Pull Latest Changes

git pull origin <branch-name>

Fetch Remote Branches

git fetch origin

6. Troubleshooting

Recover Lost Commits

git reflog                   # Find lost commits
git checkout HEAD@{1}        # Restore

Fix Merge Conflicts

  1. Open conflicted files and resolve manually.
  2. Mark as resolved:
git add <file>
git commit

Undo Last Commit

git reset --soft HEAD~1      # Keeps changes staged
git reset --hard HEAD~1      # Discards changes

Final Notes

  • Always check git status before making changes.
  • Avoid --force on shared branches unless necessary.
  • Tags are immutable—use them for releases.

For advanced Git workflows, explore:

  • git stash (temporarily save changes)
  • git rebase (rewrite commit history)
  • git cherry-pick (copy specific commits)

Let me know if you need further clarifications! 🚀