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 |
git add .
git commit -m "Describe your changes"
git push
Always pull to get the latest changes:
git pull
When pulling, conflicts may look like this:
<<<<<<< HEAD
Your local changes here
=======
Incoming changes from remote here
>>>>>>> branch-name
<<<<<<< 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");
git add <filename>
git commit -m "Resolved merge conflict"
Remove all changes (staged & unstaged) and start fresh:
git reset --hard
โ ๏ธ Warning: This cannot be undone! Changes since the last commit are lost forever.