Fetching & Pulling
How to safely download your team's changes, and the crucial difference between fetching and pulling.
git pull = fetch + merge
git fetch is a safe command that only downloads data (commits, branches, and tags) from a remote repository. It updates your remote-tracking branches (like origin/main), but it does not touch your local working files.
git pull is an aggressive command. It runs git fetch to download the data, and then immediately runs git merge to combine that data into your current working branch.
Why it matters
When working on a team, the remote repository is constantly moving forward as teammates push their work.
To see their work, review their code, or integrate their features with your own, you must bring that data down to your local machine. Understanding the difference between fetch and pull prevents you from accidentally triggering unwanted merge conflicts.
How it works
When you run git fetch, Git communicates with the remote server, grabs all the commits you don't have, and stores them locally. Your working directory remains unchanged. You can inspect the new commits safely.
When you run git pull, Git fetches that same data, but then attempts to merge it into whatever branch you are currently on. If your local work conflicts with the pulled work, the pull will halt with a merge conflict.
Separate fetching from pulling
Fetch the remote history first, then integrate it into the local branch.
Remote main: c2 Local main: c1 Last fetched origin/main: c1
Remote main
Local origin/main
Working branch: main
Fetch updates remote-tracking references without integrating them into your working branch. This linear example uses --ff-only; divergent branches require a different integration decision. Local simulation.
Check yourself
Pick an answer to lock it in, then read why. Getting one wrong is part of how it sticks.
Remember this
git pull=git fetch+git merge.git fetchsafely downloads data without touching your files.- Always commit or stash your work before running
git pull.
Done with this concept?
Mark it complete to track your progress. No login needed.