Easier to read with cream paper, a tint, more contrast or larger text? Choose your colours and text, once, for every page.

Free lesson

Open and merge a pull request in Gitea

After this lesson: I can push a branch, open a pull request on a server and merge it.

60 min lesson13 commandsGit and Gitea lab: learn clone, commit and push on a Git server of your own

A pull request on a real server

A team keeps its code on a server such as Gitea or GitHub. Nobody changes the main branch directly. You push a branch, open a pull request, and a colleague reads it first.

In this lesson you do the whole thing against the lab's Gitea, from a push to a merge.

By the end of this lesson

Note

I can push a branch, open a pull request on a server and merge it.

Key words

WordWhat it means
Pull requesta request to merge a branch, with a page to review it
APIa way for a program to ask a server to do something
Mergeableable to merge with no conflict
Merge commita commit with two parents that joins two branches
Upstreamthe remote branch your branch is linked to

The cells students fill in are left blank in this preview.

A branch must be on the server first

A pull request needs the branch to exist on the server, so you push it. Git cannot open the pull request for you.

First make a repository on Gitea. A program can do that by calling its API. The -u of git push links your branch to its remote twin, the upstream. The lab's password is public, so it is safe to type in an address here. Never do that with a real password.

Make a repository on Gitea

Command
curl -s -o /dev/null -w '%{http_code}\n' -u student:student -H 'Content-Type: application/json' -d '{"name":"menu-review","auto_init":true,"default_branch":"main"}' http://gitea:3000/api/v1/user/repos

Shown here, not run. Create a free account to press Run and type it into your own lab’s terminal.

Clone it

Command
git clone http://student:student@gitea:3000/student/menu-review.git

Shown here, not run. Create a free account to press Run and type it into your own lab’s terminal.

Start a branch for the change

Command
git -C menu-review switch -c tea-price

Shown here, not run. Create a free account to press Run and type it into your own lab’s terminal.

Add a line to the README

Command
printf 'Tea costs 2.00 from Monday.\n' >> menu-review/README.md

Shown here, not run. Create a free account to press Run and type it into your own lab’s terminal.

Commit the change

Command
git -C menu-review commit -am "Say what tea costs"

Shown here, not run. Create a free account to press Run and type it into your own lab’s terminal.

Push the branch

Command
git -C menu-review push -u origin tea-price

Shown here, not run. Create a free account to press Run and type it into your own lab’s terminal.

Open the pull request, then review it

Press New Pull Request on the repository page, or ask the API, which is what the button does. The server then works out whether the branch is mergeable.

A reviewer reads the diff and writes comments. Gitea will not let you approve your own change, so here you comment. In a team a colleague approves.

Open the pull request

Command
curl -s -o /dev/null -w '%{http_code}\n' -u student:student -H 'Content-Type: application/json' -d '{"title":"Say what tea costs","head":"tea-price","base":"main","body":"Tea costs 2.00 from Monday."}' http://gitea:3000/api/v1/repos/student/menu-review/pulls

Shown here, not run. Create a free account to press Run and type it into your own lab’s terminal.

Ask if it can merge cleanly

Command
curl -s http://gitea:3000/api/v1/repos/student/menu-review/pulls/1 | grep -o '"mergeable":[a-z]*'

Shown here, not run. Create a free account to press Run and type it into your own lab’s terminal.

Write a review comment

Command
curl -s -o /dev/null -w '%{http_code}\n' -u student:student -H 'Content-Type: application/json' -d '{"body":"Looks right to me."}' http://gitea:3000/api/v1/repos/student/menu-review/issues/1/comments

Shown here, not run. Create a free account to press Run and type it into your own lab’s terminal.

Read the diff as a reviewer

Command
curl -s http://gitea:3000/api/v1/repos/student/menu-review/pulls/1.diff

Shown here, not run. Create a free account to press Run and type it into your own lab’s terminal.

Merging happens on the server

When the review is done, someone presses Merge. The server makes a merge commit on main. Your own computer knows nothing about it yet.

So you run git fetch, which downloads what is new without changing your files. Then you read the history of origin/main, the copy Git keeps of the server's branch.

Merge the pull request

Command
curl -s -o /dev/null -w '%{http_code}\n' -u student:student -H 'Content-Type: application/json' -d '{"Do":"merge"}' http://gitea:3000/api/v1/repos/student/menu-review/pulls/1/merge

Shown here, not run. Create a free account to press Run and type it into your own lab’s terminal.

Download what is new

Command
git -C menu-review fetch

Shown here, not run. Create a free account to press Run and type it into your own lab’s terminal.

Draw the history of main on the server

Command
git -C menu-review --no-pager log --graph --format=%s origin/main

Shown here, not run. Create a free account to press Run and type it into your own lab’s terminal.

A common mistake

Warning

Many people think that merging a pull request changes the files on their own computer. It does not. The merge happens on the server. Run git fetch to see it. Then switch to main and run git pull to bring it into your own main.

About this lab and its source: Git and Gitea lab: learn clone, commit and push on a Git server of your own

Teaching a class? Set this module for your students with a teacher guide, marked assignments and a lab for every student.