Linux Labs

Automation: Git and Ansible / Stage 2 of 6

Config from a repository: pull and conflicts

Not running Starting usually ~20 s
Leave the lesson

Step 2 of 7 · theory · 5 min

Where pull gets commits from

A working copy remembers the address of the shared repository and checks its own history against it.

The shared repository everyone pushes commits to is a bare repository: /srv/git/lab-site.git has no working files, only history (ls shows HEAD, objects, refs). A working copy on a server is made with git clone /srv/git/lab-site.git <directory>: git copies the history and remembers the repository's address under the name origin — git remote -v shows it.

git pull takes two steps. First git fetch downloads new commits into the origin/main branch — that is how the working copy sees what the repository holds now. The working files do not change at this point. Then pull brings those commits into your main branch and into the files. In the experience the refusal came at the second step: the commit was already downloaded, which is why status says “behind 'origin/main' by 1 commit”. More on fetch, pull and push — in the Wiki.

bash
# download new commits, leave the files alone
sudo git fetch
# what is downloaded but not applied yet
sudo git log --oneline HEAD..origin/main
Check yourself 1 question

The repository has a new commit that changes lab-site.conf. You run sudo git fetch. What happens to lab-site.conf in the working copy?

  • Markers appear during a merge when both sides changed the same lines. fetch merges nothing and does not touch files.

  • The “would be overwritten” refusal happens when bringing commits into the files. fetch does not touch files, so the edit does not get in its way.

  • Files are changed by pull's second step — bringing commits into the branch. fetch only downloads them into origin/main: git log HEAD..origin/main shows what arrived.

git fetch only downloads commits and updates origin/main. The working files and the main branch stay the same until pull brings the commits in.

Key points

  • A bare repository keeps the shared history with no working files; the working copy knows it as origin.
  • git pull is git fetch (download commits into origin/main) plus bringing them into your branch and files.
  • git log HEAD..origin/main shows commits that are downloaded but not applied yet.
Ubuntu 24.04
Loading…