What you will do
A branch is a separate line of work in the same repository. You make a change on your own branch, so the main one stays as it was, and then you merge your branch back in when you are happy with it. Teams do this for every change. You will do it once, with the repository hello-git that this lab's Gitea already holds.
Before you start
Note
Press Start the lab on the bar at the top of this lesson and wait until it says it is running. Gitea opens from the Gitea link on the bar. Each Run button below types its command into your lab's terminal, one after another in the same session. To watch them, or to type your own, press Open terminal on the bar.
1. Tell Git who you are, and get the repository
Git needs your name for every commit. Then git clone copies hello-git from Gitea into a new folder of the same name in your home folder, ~, and cd moves into it. It has two files and two commits already. The ~/ matters if you did Git Basics first: without it the copy would land inside that lesson's folder.
git config --global user.name "Student"Shown here, not run. Create a free account to press Run and type it into your own lab’s terminal.
git config --global user.email "[email protected]"Shown here, not run. Create a free account to press Run and type it into your own lab’s terminal.
git clone http://student:student@gitea:3000/student/hello-git.git ~/hello-gitShown here, not run. Create a free account to press Run and type it into your own lab’s terminal.
cd ~/hello-gitShown here, not run. Create a free account to press Run and type it into your own lab’s terminal.
2. Start your own branch
git switch -c my-change makes a new branch called my-change and moves you onto it. From now on, commits go on this branch and main does not move.
git switch -c my-changeShown here, not run. Create a free account to press Run and type it into your own lab’s terminal.
3. Make a change and commit it
Add your line to the visitors list, then stage and commit it, the same three steps as Git Basics. git log --oneline shows your commit on top of the two that were there.
echo "Your Name" >> visitors.txtShown here, not run. Create a free account to press Run and type it into your own lab’s terminal.
git add visitors.txtShown here, not run. Create a free account to press Run and type it into your own lab’s terminal.
git commit -m "Add my name to the visitors list"Shown here, not run. Create a free account to press Run and type it into your own lab’s terminal.
git --no-pager log --onelineShown here, not run. Create a free account to press Run and type it into your own lab’s terminal.
4. Push the branch
The branch only exists on your computer until you push it. -u origin my-change sends it to Gitea and remembers where it goes. git branch -a now lists the branches on both sides. Gitea also prints a link for making a pull request: it starts http://localhost, which your browser cannot reach, so use the Gitea link on the bar instead, in the next step.
git push -u origin my-changeShown here, not run. Create a free account to press Run and type it into your own lab’s terminal.
git --no-pager branch -aShown here, not run. Create a free account to press Run and type it into your own lab’s terminal.
5. Merge it in Gitea
Press the Gitea link on the lab bar and sign in as student with the password student. Open student/hello-git and press Pull Requests, New Pull Request. Choose my-change to be merged into main, press Create Pull Request, then Merge. A pull request is how a team asks to merge a branch, and where somebody else can read it first.
6. Bring the merge back
Your computer does not know about the merge yet. Switch back to main and run git pull to fetch it. git log --oneline now shows your commit and the merge.
git switch mainShown here, not run. Create a free account to press Run and type it into your own lab’s terminal.
git pullShown here, not run. Create a free account to press Run and type it into your own lab’s terminal.
git --no-pager log --onelineShown here, not run. Create a free account to press Run and type it into your own lab’s terminal.
For teachers
Tip
This lesson is a small example of a lesson worked in a lab: the steps and the Run buttons are the lesson, and the lab is each student's own copy. This lesson uses the same Gitea lab as Git Basics, so each student keeps one terminal and one history across both. A lab can back as many lessons as you like. Copy it into your own module and change it, or build one from scratch with the Lab menu in the lesson builder.