GitHub collaboration

English translation

Learning objectives

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

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.

Track changes to one file

Starting conditions

repo is temporary storage on the computer running the notebook kernel. In README.md inside it, change Condition: baseline to Condition: test.

Procedure

  1. After checking the baseline commit, read repo/'README.md' in a new code cell in the same notebook, change only the specified sentence, and save. Resolve file paths relative to repo.
  2. Call the provided git(*args) function in a code cell and record the diff and status. For example, you can display changes with print(git('diff')).
  3. Commit the changes, then check the difference from the previous commit again.

Results to retain

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'))

Record results and self-check

Step:

File contents:

Working tree status:

Commit message:

Points to check

Separate experimental conditions with branches

Starting conditions

Create an experiment branch in the same repository and add Rate: 10 Hz to README.md.

Procedure

  1. After committing on experiment, return to main and compare the file contents.
  2. Inspect both branches' histories with log –oneline –all –graph.
  3. After merging into main, describe what remains in the file and history.

Results to retain

# Use repo and the git function from the previous cell.
print(git('branch','--show-current'))
# TODO: Create the experiment Branch and record changes, commits, and merges.

Record results and self-check

Branch and step:

README contents:

HEAD Commit:

Location of the change:

Points to check

Reproduce and resolve a conflict

Starting conditions

Change the same Condition line to different values on main and experiment, and commit each change.

Procedure

  1. Attempt the merge and keep the file containing conflict markers.
  2. Resolve the conflict by writing the final selected condition on one line, then commit.
  3. Explain the difference between editing different lines and editing the same line.

Results to retain

print(git('status','--short'))
# TODO: Create a conflict on the same line and record the final changes.

Record results and self-check

Scenario:

Merge result:

Selected final sentence:

Reason for selection:

Points to check