Chapter 2 · Git and GitHub
Pull Requests, README and Your First Published Project
- Page 10 of 22
- 19 min read
On a real team nobody pushes straight to main. You work on a branch, push it, and open a pull request (PR): a page on GitHub that says "please merge this branch into main", shows exactly what changes, and lets teammates comment, request changes and approve. Automated checks (tests, linters) run on it too. Only then is it merged.
Pull requests are how almost all software, including every big AI library, is built. They are also how you contribute to open source and how a reviewer judges your work. This page takes a small fix all the way through: an issue, a branch, a pull request with a good description, a review, the merge and the clean-up. Along the way you write a README people can actually use and publish the project properly.
What you will learn
- What makes a README useful, with a template for AI projects.
- The pull-request workflow: issue → branch → push → PR → review → merge → clean up.
- Writing a PR description reviewers can act on, and linking issues with
Closes #1. - Merge commit vs squash vs rebase merging on GitHub, and what each does to history.
- A checklist for publishing your first project, and a first look at the
ghcommand-line tool.
Set up the example project
The review analyser again, already pushed to a remote. As on the previous page, a bare repository in ~/remotes stands in for GitHub, and Rafi's clone stands in for a teammate. The sample data includes a review the analyser gets wrong:
mkdir -p ~/projects/review-analyser
cd ~/projects/review-analyser
git init -q
cat > words.py <<'EOF'
POSITIVE = {"good", "great", "fast", "love"}
NEGATIVE = {"bad", "slow", "broken", "late"}
EOF
cat > analyse.py <<'EOF'
"""Label product reviews as positive, negative or neutral."""
import csv
from words import NEGATIVE, POSITIVE
def label(text):
words = text.lower().split()
score = sum(w in POSITIVE for w in words) - sum(w in NEGATIVE for w in words)
return "positive" if score > 0 else "negative" if score < 0 else "neutral"
if __name__ == "__main__":
with open("reviews.csv", newline="", encoding="utf-8") as f:
for row in csv.DictReader(f):
print(label(row["text"]), "|", row["text"])
EOF
cat > reviews.csv <<'EOF'
id,text
1,great phone and fast delivery
2,battery is bad and the box was broken
3,not good at all
EOF
printf '.env\n.venv/\n__pycache__/\n' > .gitignore
git add .
git commit -q -m "Add keyword review analyser"
git init -q --bare ~/remotes/review-analyser.git
git remote add origin ~/remotes/review-analyser.git
git push -q -u origin main
git clone -q ~/remotes/review-analyser.git ~/rafi/review-analyser
git -C ~/rafi/review-analyser config user.name "Rafi Ahmed"
git -C ~/rafi/review-analyser config user.email "[email protected]"
python analyse.pypositive | great phone and fast delivery
negative | battery is bad and the box was broken
positive | not good at allA README that helps
The README is the front page of your repository: GitHub shows it below the file list. A visitor decides in about thirty seconds whether your project is useful, and a teammate (or you, in six months) needs it to run the code. A good README answers, in this order:
| Section | Answers | AI-project specifics |
|---|---|---|
| Title + one or two sentences | What is this, and why would I care? | Task, input and output ("labels reviews as positive/negative/neutral") |
| Quick start | How do I run it, in commands I can copy? | Python version, install command, cp .env.example .env if keys are needed |
| Example | What does it actually do? | A real input and the real output |
| How it works | Where do I look in the code? | Model or method, where the data and model files come from |
| Limitations | When should I not trust it? | Languages, data it was not tested on, known failure cases, evaluation results |
| Licence | May I use it? | Licence of the code, and of the data or model weights if different |
READMEs are written in Markdown: # for headings, **bold**, - for lists, backticks for code, and fenced blocks between three backticks for commands. Create one for the analyser:
cat > README.md <<'EOF'
# Review analyser
Labels product reviews as **positive**, **negative** or **neutral** using two
small keyword lists: a simple baseline to compare ML models and LLMs against.
## Quick start
```bash
git clone https://github.com/nadia-rahman/review-analyser.git
cd review-analyser
python analyse.py
```
Needs Python 3.12 or newer; no extra packages.
## Example
`reviews.csv` contains `1,great phone and fast delivery`, and the output is:
```text
positive | great phone and fast delivery
```
## How it works
`words.py` holds the keyword lists. `analyse.py` counts positive words minus
negative words in each review and turns the score into a label.
## Limitations
- English only; no sarcasm, emoji or context.
- The word lists are small and hand-made.
## Licence
MIT
EOF
git add README.md
git commit -q -m "Write a README with quick start, example and limitations"
git push -qSmall, honest, and runnable. Notice the "Limitations" section: for anything with a model in it, saying where it fails is part of doing the job well, not an admission of weakness.
Start from an issue
Review 3 above, "not good at all", is labelled positive. On GitHub, problems and ideas are tracked as issues: open the repository's Issues tab → New issue, give it a clear title and enough detail to reproduce the problem, and optionally a label such as bug. Nadia files this:
Title: "not good" is labelled positive
Steps: python analyse.py with review 3, "not good at all".
Expected: negative
Actual: positive
The analyser ignores "not" before a keyword.GitHub gives it the number #1. Issues and pull requests share one numbering sequence in a repository, so the pull request we open next will be #2. Issues also hold feature requests, questions and to-do lists; labels, assignees and milestones organise them.
The pull-request workflow
issue #1 --> branch fix/1-negation --> commits --> git push -u --> open PR #2
|
main <-- merge <-- approve <-- review comments <-- push more commits1. Branch from an up-to-date main
Always start from the latest main, so your branch does not begin out of date. Naming the branch after the issue makes the link obvious:
git switch main
git pull
git switch -c fix/1-negationAlready on 'main'
Your branch is up to date with 'origin/main'.
Already up to date.
Switched to a new branch 'fix/1-negation'2. Commit the change
cat > analyse.py <<'EOF'
"""Label product reviews as positive, negative or neutral."""
import csv
from words import NEGATIVE, POSITIVE
def label(text):
words = text.lower().split()
score = 0
for i, w in enumerate(words):
sign = -1 if i > 0 and words[i - 1] == "not" else 1
score += sign * ((w in POSITIVE) - (w in NEGATIVE))
return "positive" if score > 0 else "negative" if score < 0 else "neutral"
if __name__ == "__main__":
with open("reviews.csv", newline="", encoding="utf-8") as f:
for row in csv.DictReader(f):
print(label(row["text"]), "|", row["text"])
EOF
python analyse.py
git commit -q -am "Flip the score of a keyword that follows not"positive | great phone and fast delivery
negative | battery is bad and the box was broken
negative | not good at all3. Push the branch
git push -u origin fix/1-negationTo /home/nadia/remotes/review-analyser.git
* [new branch] fix/1-negation -> fix/1-negation
branch 'fix/1-negation' set up to track 'origin/fix/1-negation'.On GitHub, the push output also contains remote: Create a pull request for 'fix/1-negation' on GitHub by visiting: followed by a link, and the repository page shows a yellow banner with a Compare & pull request button.
4. Open the pull request
Click the button (or Pull requests → New pull request), then:
- Check the branches: base:
main← compare:fix/1-negation. The base is where the changes will go. - Write a title that says what the PR does: Handle negation: "not good" is negative.
- Write the description (below).
- On the right: request a reviewer (Rafi), add a label, assign yourself.
- Click Create pull request, or choose Create draft pull request from the button's menu if it is not ready for review yet.
A description reviewers can act on
The reviewer was not in your head while you worked. Tell them what changed, why, how you checked it, and what you want them to look at:
## What
A keyword right after "not" now counts the opposite way, so
"not good" scores -1 instead of +1.
## Why
Reviews like "not good at all" were labelled positive.
Closes #1
## How I tested it
python analyse.py on reviews.csv: review 3 is now negative,
reviews 1 and 2 are unchanged.
## Notes for the reviewer
Only "not" is handled. "never", "no" and "isn't" are left for a
follow-up; is that OK?Closes #1 (also Fixes or Resolves) links the issue: when the PR is merged into the default branch, GitHub closes issue #1 automatically. Keep PRs small and about one thing; a 50-line PR gets a careful review, a 2,000-line one gets "looks good to me". For UI changes add a screenshot; for model changes add the evaluation numbers before and after.
5. Review
The reviewer reads the Files changed tab, can click any line to leave a comment (or a suggestion you can apply with one click), and finishes with Comment, Approve or Request changes. A good reviewer also runs the code. Rafi does that from his clone: he fetches, switches to the PR branch, and looks at exactly what the PR changes:
cd ~/rafi/review-analyser
git fetch -q
git switch fix/1-negation
git log --oneline origin/main..origin/fix/1-negation
git diff --stat origin/main...origin/fix/1-negation
python analyse.pySwitched to a new branch 'fix/1-negation'
branch 'fix/1-negation' set up to track 'origin/fix/1-negation'.
7a86d1d Flip the score of a keyword that follows not
analyse.py | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
positive | great phone and fast delivery
negative | battery is bad and the box was broken
negative | not good at allorigin/main..BRANCH lists the commits on the branch that main on the remote does not have (the PR's Commits tab), and git diff origin/main...BRANCH, with three dots, shows the changes since the branch started (the Files changed tab). Rafi answers Nadia's question: "Please handle never too, it is common in reviews." He clicks Request changes.
6. Update the pull request
You don't open a new PR for feedback. Commit on the same branch and push: the PR updates itself and the reviewer sees the new commit.
cd ~/projects/review-analyser
cat > analyse.py <<'EOF'
"""Label product reviews as positive, negative or neutral."""
import csv
from words import NEGATIVE, POSITIVE
NEGATORS = {"not", "never"}
def label(text):
words = text.lower().split()
score = 0
for i, w in enumerate(words):
sign = -1 if i > 0 and words[i - 1] in NEGATORS else 1
score += sign * ((w in POSITIVE) - (w in NEGATIVE))
return "positive" if score > 0 else "negative" if score < 0 else "neutral"
if __name__ == "__main__":
with open("reviews.csv", newline="", encoding="utf-8") as f:
for row in csv.DictReader(f):
print(label(row["text"]), "|", row["text"])
EOF
echo "4,never fast enough" >> reviews.csv
python analyse.py
git commit -q -am "Treat never like not, as asked in review"
git push -qpositive | great phone and fast delivery
negative | battery is bad and the box was broken
negative | not good at all
negative | never fast enoughRafi re-reviews and clicks Approve. On a protected main (rulesets, in the advanced tutorial), GitHub can require an approval and passing checks before the merge button turns green.
7. Merge
The Merge pull request button has three modes. Repository owners choose which are allowed under Settings → General → Pull Requests.
| Button | What lands on main | Good for |
|---|---|---|
| Create a merge commit (default) | All the branch's commits plus a merge commit "Merge pull request #2 from …" (like git merge --no-ff) | Keeping the full story of each PR |
| Squash and merge | One new commit containing all the PR's changes | PRs with messy "fix typo" commits; a tidy one-commit-per-PR history |
| Rebase and merge | The branch's commits replayed one by one onto main, no merge commit | Linear history with each commit kept |
Nadia's PR uses the default. To see what the button does in Git terms, here Rafi does the very same merge in his clone and pushes it. On GitHub you just click Merge pull request → Confirm merge, then Delete branch:
cd ~/rafi/review-analyser
git switch -q main
git pull -q
git merge --no-ff -m "Merge pull request #2 from nadia-rahman/fix/1-negation" origin/fix/1-negation
git push -q
git push origin --delete fix/1-negationMerge made by the 'ort' strategy.
analyse.py | 7 ++++++-
reviews.csv | 1 +
2 files changed, 7 insertions(+), 1 deletion(-)
To /home/nadia/remotes/review-analyser.git
- [deleted] fix/1-negation8. Clean up locally
Back on her machine, Nadia updates main, deletes her finished branch, and prunes the remote-tracking branch that no longer exists on the remote:
cd ~/projects/review-analyser
git switch main
git pull -q
git branch -d fix/1-negation
git fetch --prune
git log --oneline --graph --decorateSwitched to branch 'main'
Your branch is up to date with 'origin/main'.
Deleted branch fix/1-negation (was 6c272cb).
From /home/nadia/remotes/review-analyser
- [deleted] (none) -> origin/fix/1-negation
* 153381b (HEAD -> main, origin/main) Merge pull request #2 from nadia-rahman/fix/1-negation
|\
| * 6c272cb Treat never like not, as asked in review
| * 7a86d1d Flip the score of a keyword that follows not
|/
* cd2ea36 Write a README with quick start, example and limitations
* 4217c26 Add keyword review analyserThe graph shows the whole PR: the branch's two commits and the merge commit that brought them into main. Run git config --global fetch.prune true once and every fetch and pull prunes deleted branches automatically. Then the cycle starts again: new issue, new branch from an up-to-date main.
Publishing your first project
Before you share a repository link in a CV, a course submission or LinkedIn, go through this list:
- README with a one-line purpose, quick start, an example and limitations.
- Licence: without one, others may legally not reuse your code. On GitHub: Add file → Create new file, name it
LICENSE, and pick a template (MIT is short and permissive). Mention the licence of any dataset or model weights you use. .gitignoreand no secrets in history:git log -p -S "sk-"(and for other key prefixes) finds nothing, and.env.examplelists the settings.- Dependencies declared:
requirements.txtorpyproject.toml(and a lockfile with uv), so the quick start really works on a fresh machine. Try it: clone into a new folder and follow your own README. - Small sample data in the repository, large data and models linked or downloadable, never committed.
- On the repository page, the About box (gear icon): a description, topics such as
nlp,sentiment-analysis,python, and a website link if there is a demo. - Visibility public when all of the above is true. Then pin it on your GitHub profile (Customize your pins). A repository named exactly like your username, with a README, becomes your profile page.
A first look at gh, the GitHub CLI
Everything you did in the browser can also be done from the terminal with gh (version 2.x), GitHub's official command-line tool. Install it from cli.github.com (or winget install GitHub.cli, brew install gh), then log in once. These commands talk to the real GitHub, so they are shown here, not run:
gh auth login # GitHub.com, HTTPS, log in with a browser
gh repo create review-analyser --public --source=. --remote=origin --push
gh issue create --title '"not good" is labelled positive' --body "Review 3 is wrong." --label bug
gh pr create --base main --head fix/1-negation --title "Handle negation" --body "Closes #1" --reviewer rafi-ahmed
gh pr list # open pull requests
gh pr checkout 2 # a reviewer gets the PR's branch locally
gh pr review 2 --approve
gh pr merge 2 --merge --delete-branch # or --squash / --rebasegh repo create … --source=. --push creates the GitHub repository from your local one, adds origin and pushes in one step. gh pr create without options asks for everything interactively, and gh pr view --web opens the PR in the browser. gh auth login also configures Git to use your GitHub login for HTTPS pushes, so you never handle a token by hand.
Where this shows up in real AI work
- Every change to a production AI system (a new prompt, a model version bump, a feature in the inference API) goes through a PR, so at least one other person has looked at it and the tests ran.
- Model and prompt changes in PRs come with evaluation results in the description: accuracy or win rate before and after, and examples that changed.
- Open source: Hugging Face Transformers, scikit-learn, FastAPI and LangChain all take contributions only as pull requests from forks (the advanced tutorial covers forks). Reading their PR discussions is a free lesson in engineering.
- AI coding assistants increasingly open PRs themselves; reviewing a PR carefully is now a core skill, whoever wrote the code.
Common mistakes
- Branching from an old
main. The PR then shows unrelated changes or conflicts. Fix:git switch main,git pull, then create the branch. - Huge pull requests. Nobody can review 40 files properly. Fix: one topic per PR, a few hundred lines at most; split refactors from features.
- Empty descriptions. "Fixed stuff" forces the reviewer to guess. Fix: what, why, how tested, what to look at, and
Closes #N. - Opening a new PR for every round of feedback. The discussion gets scattered. Fix: push new commits to the same branch; the PR updates.
- Forgetting to clean up. Dozens of stale branches hide the live ones. Fix: delete the branch on GitHub after merging,
git branch -dlocally,fetch.pruneon.
Try it yourself
- Easy: Write a PR title and description for this change: "Adds excellent to the positive words and awful to the negative words, because 12 of 200 hand-labelled reviews used them and were labelled neutral; fixes issue #4."
- Medium: Start a branch
docs/negationfrom an up-to-datemain, add a line toREADME.mdexplaining that "not" and "never" flip the next keyword, commit and push it with an upstream. Then show what a reviewer would see: the PR's commits and its changed files. - Hard: This time the PR is merged with Squash and merge. Simulate it in Rafi's clone (
git merge --squash, then a commit titledExplain negation in the README (#3), push, delete the remote branch). Then clean up in Nadia's repository. Why doesgit branch -d docs/negationrefuse, and what do you do?
Answers
Easy, one good answer:
Title: Add "excellent" and "awful" to the keyword lists
## What
Adds "excellent" to POSITIVE and "awful" to NEGATIVE in words.py.
## Why
12 of 200 hand-labelled reviews contain one of these words and were
labelled neutral. Closes #4
## How I tested it
python analyse.py on the labelled sample: those 12 reviews now get
the right label; no other label changed.# Medium
cd ~/projects/review-analyser
git switch main
git pull -q
git switch -c docs/negation
printf '\n"not" and "never" flip the score of the keyword after them.\n' >> README.md
git commit -q -am "Explain negation in the README"
git push -q -u origin docs/negation
git log --oneline main..docs/negation
git diff --stat main...docs/negationAlready on 'main'
Your branch is up to date with 'origin/main'.
Switched to a new branch 'docs/negation'
dc49360 Explain negation in the README
README.md | 2 ++
1 file changed, 2 insertions(+)# Hard: Rafi presses "Squash and merge"
cd ~/rafi/review-analyser
git pull -q
git merge --squash origin/docs/negation
git commit -q -m "Explain negation in the README (#3)"
git push -q
git push -q origin --delete docs/negation
# Nadia cleans up
cd ~/projects/review-analyser
git switch -q main
git pull -q
git fetch -q --prune
git branch -d docs/negationUpdating 153381b..dc49360
Fast-forward
Squash commit -- not updating HEAD
README.md | 2 ++
1 file changed, 2 insertions(+)
error: the branch 'docs/negation' is not fully merged.
If you are sure you want to delete it, run 'git branch -D docs/negation'(git merge --squash reports Squash commit -- not updating HEAD: it stages the combined changes without committing, and the next git commit makes the single squash commit.) A squash merge creates a new commit with the same changes; the branch's own commit never became part of main, so -d sees it as unmerged and refuses (the exact wording of the message varies between Git versions). You have checked that the PR was merged, so force it:
git branch -D docs/negation
git log --oneline -3Deleted branch docs/negation (was dc49360).
a482060 Explain negation in the README (#3)
153381b Merge pull request #2 from nadia-rahman/fix/1-negation
cd2ea36 Write a README with quick start, example and limitationsSummary
- A README says what the project does, how to run it (copyable commands), an example, how it works, its limitations and its licence.
- The PR workflow: issue → branch from an up-to-date
main→ commits →git push -u→ pull request → review → more commits on the same branch → merge → delete the branch andgit pull. - A good PR is small, has a clear title and a description with what, why, how tested and
Closes #N. - GitHub merges with a merge commit (default), a squash commit or a rebase; after a squash, delete the local branch with
-D. - Before publishing: README, licence,
.gitignore, no secrets in history, dependencies, sample data, About box and topics.ghdoes all of this from the terminal.
Next: How the Web Works: Clients, Servers and HTTP. Your code now lives on GitHub; next you start on the other half of this topic: what actually happens when one program talks to another over the web, the foundation for every API you will call and build.

