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

Conflict: both sides changed the same line

If a colleague and the server changed the same lines, git does not choose for you — it puts both versions into the file.

A merge or git stash pop carries edits over line by line. When both sides changed the same line, you get a conflict (in the Wiki): git says CONFLICT (content): Merge conflict in <file>, and git status says both modified. In the file, markers appear where the line was:

text
<<<<<<< Updated upstream
the repository's version
=======
your set-aside version
>>>>>>> Stashed changes

A conflict is resolved by hand: keep what you need — one version or a line built from both — and delete the three marker lines. With markers in it the config fails sudo nginx -t. Then git add <file> tells git the conflict is resolved. After a conflict stash pop does not delete the set-aside edit — “The stash entry is kept in case you need it again”; once the edit is in the file, git stash drop removes the entry.

Exercise · do it

Update the server when the edits collide

/etc/nginx/conf.d has a local edit again, and the repository has a new commit from a colleague, and each added a site name to the server_name line. Update the working copy to the repository's version so that the config keeps both new names, passes nginx -t, and no set-aside edits remain.

Sign in and start The machine is available after signing in

Goals · 0 of 2

  • Update the working copy, leaving no set-aside edits not done yet
  • Keep both names in the config without conflict markers not done yet

Step goals

0 of 2
  • Update the working copy, leaving no set-aside edits — not done yet
  • Keep both names in the config without conflict markers — not done yet
Ubuntu 24.04

Step goals

0 of 2
  • Update the working copy, leaving no set-aside edits — not done yet
  • Keep both names in the config without conflict markers — not done yet
Loading…