GitHub collaboration · Learning

English translation

Execution conditions

The baseline exercise uses a temporary local Git repository. You can explore changes, branches, and merges without a GitHub account or a remote repository connection.

Topics covered

Use a safe local example to learn how to combine changes without losing them when several people edit the same file.

Overall workflow

Edit file → diff/commit → branch/merge → verify final content

A commit is a point for comparison

Saving a file and making a Git commit are different. Record changes in small, meaningful units and read the diff to see what changed. A branch names a line of history for separate experiments.

Resolving a conflict means choosing the intended result

When the same line is changed differently, Git cannot decide the correct final content. Read the purpose of both changes, keep the intended content, and run it again to check. Simply deleting conflict markers does not complete verification.

Worked example

In README.md in the temporary repository created by the code, change Condition: baseline to Condition: test.

from pathlib import Path
import tempfile, subprocess
lab_tmp=tempfile.TemporaryDirectory(prefix='course-git-')
repo=Path(lab_tmp.name)
def git(*args):
    return subprocess.check_output(['git','-C',str(repo),*args],text=True).strip()
git('init','-b','main');git('config','user.name','Learner');git('config','user.email','learner@example.invalid')
(repo/'README.md').write_text('Robot experiment\nCondition: baseline\n')
git('add','README.md');git('commit','-m','Record baseline')
print(repo,git('log','--oneline'))
/var/folders/w7/d9v_mh_s5gbgqlr6pvxd72t40000gn/T/course-git-ecbsztiq e629da2 Record baseline

Reference example

View more examples

Reference materials