codex-lv2-may-2025

πŸ“„ Git Beginner Cheat Sheet


βœ… Common Git Commands

Command What it Does
git init Starts a new Git repository
git status Shows changed, staged, and untracked files
git log Shows commit history
git add <filename> Stages a specific file
git add . Stages all changes
git commit -m "Your message" Commits staged changes
git push Pushes commits to the remote repo
git pull Fetches and merges remote changes

πŸš€ ACP Workflow (Add, Commit, Push)

  1. Add
git add .
  1. Commit
git commit -m "Describe your changes"
  1. Push
git push

πŸ”„ Update Before Pushing

Always pull to get the latest changes:

git pull

Note that if you get an error saying β€œhint: You have divergent branches and need to specify how to reconcile them.”, you can use this command to tell it to merge by default:

git config pull.rebase false

You can configure this once for all repos using the --global flag:

git config --global pull.rebase false

🧨 Merge Conflicts

When pulling, conflicts may look like this:

<<<<<<< HEAD
Your local changes here
=======
Incoming changes from remote here
>>>>>>> branch-name

What to Do:

  1. Manually edit to fix the conflict Open the file in your code editor. Look for the conflict markers:

    • <<<<<<< HEAD
    • =======
    • >>>>>>> branch-name

    Decide which code to keep, or combine both parts if needed. Then delete the conflict markers and any unwanted lines.

Example: Before fixing:

<<<<<<< HEAD
console.log("Hello from my changes");
=======
console.log("Hello from the team's changes");
>>>>>>> main

After fixing:

console.log("Hello from my changes");
// or merge them:
console.log("Hello from my changes and the team's changes");
  1. Stage the resolved file:
git add <filename>
  1. Commit the merge:
git commit -m "Resolved merge conflict"

πŸ” Restart: Undo All Changes Since Last Commit

Remove all changes (staged & unstaged) and start fresh:

git reset --hard

⚠️ Warning: This cannot be undone! Changes since the last commit are lost forever.