Git Workflows
Git is the version control system that nearly every software team uses. Knowing the commands is one thing; understanding the workflow is what makes you effective on a team.
Branches
A branch is a movable pointer to a sequence of commits. The default branch (usually main) holds the shared, production-ready code. Each new feature or bug fix lives on its own short-lived branch:
git checkout -b feature/login
Working on a branch means your changes do not disturb anyone else's work, and switching branches snaps your working directory back to a clean state.
Merge vs Rebase
When your branch is done, you have two ways to bring it into main:
- Merge creates a new "merge commit" that ties both histories together. The history is honest — it shows exactly what happened — but can get tangled when many branches merge in parallel.
- Rebase replays your branch's commits on top of the latest
main, producing a single straight line. The history is cleaner, but you have rewritten commits and must never rebase a branch other people share.
A common rule: rebase your local feature branch to keep it tidy, then merge it into main with a merge commit (or "squash and merge") at the end.
The Pull Request Flow
Most teams require code to enter main through a pull request (PR), also called a merge request:
- Branch off
main - Commit your changes locally
- Push the branch and open a PR
- Reviewers leave comments; you push fixes
- CI runs tests automatically
- When approved and green, merge into
main
The PR is where code review, automated checks, and conversation about the change all happen.
Resolving Conflicts
If two branches change the same lines, git cannot merge automatically. You will see conflict markers (<<<<<<<, =======, >>>>>>>) in the affected files. Edit them down to the version you want, stage the file, and finish the merge or rebase. Pulling from main often before you finish a long-running branch keeps conflicts small.
Try It Yourself
- Find the merge base between two branches in a real repo using
git merge-base - Try
git rebase -i HEAD~3to squash three commits into one - Open a PR for a typo fix in a project you are familiar with