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 1 of 7 · on a machine · 5 min

git pull refuses

What you will learn

  • Explain where git pull gets commits from and why it refuses, from the output of git status and git log HEAD..origin/main.
  • Update a working copy without losing a local edit: git stash, git pull, git stash pop.
  • Send your commit with git push and resolve a conflict in a file from both versions.

The team keeps the lab-site config in a shared repository /srv/git/lab-site.git, and the /etc/nginx/conf.d directory on the server is its working copy. This morning a colleague pushed a new /status page to the repository, and the server needs updating: fresh commits are fetched by git pull. Try it — and see what state the working copy is left in.

Exercise · look

Try to update the server from the repository

In /etc/nginx/conf.d pull the update from the repository, then look at the state of the working copy.

First, predict

The repository has a new commit, and on the server someone edited the same file without committing. What will sudo git pull do?

Now start the exercise, run the command and compare your prediction with the output.

Sign in and start The machine is available after signing in
Check yourself 1 question

git pull downloaded the colleague's commit but did not bring it into the files. What stopped it?

  • The commit is downloaded: status says “behind by 1 commit”, and sudo git log --oneline HEAD..origin/main shows it. The refusal is at bringing it into the files.

  • The command ran with sudo, as root. A permission error would read “Permission denied”, while git said “would be overwritten by merge”.

  • The lines differ: the commit adds /status at the end of the file, the edit adds access_log near the top. git refuses on any uncommitted edit to a file the new commit changes.

git does not overwrite an edit that is not in the history and refuses to bring a commit into such a file.

Ubuntu 24.04
Loading…