To avoid conflicts when collaborating, you should always pull before pushing when working with partners. Here’s a safe and common workflow:
git branch
Switch if needed:
git checkout main
git add .
git commit -m "Your message"
git pull
If you’re working on main:
git pull origin main
git push
<<<<<<<, =======, >>>>>>>.git add <file>
git commit
git push
To reduce unnecessary merge commits:
git pull --rebase
This applies your commits on top of the latest remote commits.
| Step | Command |
|---|---|
| 1 | git add . |
| 2 | git commit -m "" |
| 3 | git pull |
| 4 | Resolve conflicts if needed |
| 5 | git push |
This habit keeps your local branch up to date before pushing, reducing the chance of conflicts.