Hands-On Tutorial
1. Explore the Repository
Section titled “1. Explore the Repository”Before making any changes, take a few minutes to familiarize yourself with the repository.
-
Open the repository. Do not forget to log in to your GitHub account, if prompted.
-
Read the README. Most repositories start with a
README.mdfile displayed on the main page. There the main purpose and structure of the project is explained. Read it carefully. -
Browse the files. Click on folders and files to explore what is already there. Use the breadcrumb trail at the top to navigate back.
-
Check the existing branches. Click on the branch dropdown (it shows
mainby default) near the top-left of the file list. This lists all branches in the repository. Themainbranch contains the stable, reviewed version of the project. At this point you will probably only see themainbranch in this list. -
Check the commit history. Under the green
<> Codebutton you will see a 🕓Commitslink with a count. Click it to see all commits. Notice the author name, the commit message, and the timestamp. -
View the network graph. Go to the
Insightstab at the top of the repository, then clickNetworkin the left sidebar. This shows a visual timeline of all branches and commits. At this point you will probably only see themainbranch as a straight line. Keep this view in mind as you will come back to it later to see how your branch fits in.
2. Plan your Work and Create an Issue
Section titled “2. Plan your Work and Create an Issue”In a real project, work is always planned and tracked before any code or text is changed. GitHub Issues are the place to do that. You will now create an issue to describe the contribution you are going to make in this tutorial.
-
Go to the Issues tab. Click on 🔘
Issuesin the top navigation of the repository. -
Create a new issue. Click the green
New issuebutton in the top-right corner. -
Write a clear title. The title should describe what you plan to do.
-
Add a description. In the text area below, briefly explain why this change is needed. You can use Markdown syntax to format text.
-
Assign yourself. On the right-hand side, click
Assigneesand select your own GitHub username. Adding an assignee signals to the team that there is a person responsible for this task. -
Add a label. Click
Labelsand select a relevant label. This helps with filtering and prioritizing issues. -
Submit the issue. Click the green
Createbutton. You will be taken to the issue page. Note the issue number (e.g.,#7) shown next to the title - you will need it later.
3. Create a Branch
Section titled “3. Create a Branch”It is strongly recommended to never work directly on the main branch.
Instead, it is best to create a dedicated branch for every change that you plan to make, so that your work stays isolated until it is ready to be reviewed and merged.
You will now create a new branch to address the issue that you just created. The easiest way to create a branch that is automatically linked to your issue is to do it directly from the issue page.
-
Go to your issue page. You should still have it open from before.
-
Find the Development section. On the right-hand side panel, scroll down until you see the
Developmentsection. ClickCreate a branch. -
Choose a branch name. GitHub suggests a name based on the issue number and title, for example
7-issue-name. It is best to keep this name as it clearly links the branch to the issue. You can of course shorten it if it is too long, but remember to keep the issue number at the start of the branch name. -
Leave the other options at their defaults.
- Repository destination: the shared repository
- Branch source:
main
-
Click the green
Create branchbutton. GitHub may show a dialog withgitcommands to checkout locally. You can ignore this since for this tutorial we will only work in the browser. -
Switch to your new branch. Go to the repository home page and click on the branch dropdown. Select your new branch from the list and the page will reload showing your branch. Notice the branch name is now shown in the dropdown, instead of
main.
4. Make a Change and Commit It
Section titled “4. Make a Change and Commit It”Now that you are on your own branch, you can safely make changes without affecting anyone else’s work.
-
Navigate to the folder where you want to add a text file.
-
Create a new file. Click the
Add filebutton at the top-right area of the file list and selectCreate new file. -
Name your file. In the filename field at the top, type the path to your file, followed by the file’s name.
-
Write your content. In the editor, add a few lines. This does not need to be perfect now, we will come back to edit the content later.
-
Commit your change. Click the
Commit changes...button in the top-right. A dialog box will appear. -
Write a meaningful commit message. Replace the default message with something descriptive. Optionally add an extended description if there is more context to provide.
-
Make sure the correct branch is selected. The dialog should show “Commit directly to the
7-your-branchbranch”. Do not selectmain. -
Finish the commit. Click the
Commit changesbutton. Your file is now saved and tracked in your branch.
5. Open a Pull Request
Section titled “5. Open a Pull Request”A Pull Request, also known as PR, is a formal request to merge your branch into main.
It is also the space where collaborators review your changes and give feedback.
-
Start a new pull request. Go to the
Pull requeststab. Click the greenNew pull requestbutton. -
Select your branch.
Base branch:main(this is where your changes will be merged into)Compare branch: your branch (e.g.,7-your-branch)
After selecting, GitHub will show you a diff — the exact changes you are proposing.
-
Start the pull request creation. Click the green
Create pull requestbutton. -
Write a title and description.
- The PR title should be concise and descriptive.
- In the description, explain what your PR does and why. Then link it to your issue by adding a line like:
Closes #7where you replace
7with your actual issue number. When the PR gets merged, GitHub will automatically close the linked issue. -
Request a reviewer. On the right-hand side, click
Reviewersand select a classmate to review your PR. Ask the classmate sitting next to you - you will review each other’s PRs. -
Finish the pull request creation. Click the green
Create pull requestbutton. Your PR is now open and your reviewer will be notified.
6. Review a Pull Request
Section titled “6. Review a Pull Request”While you wait for your reviewer to look at your PR, it is your turn to review a PR. Maybe a classmate has already assigned one to you. Reviewing is an essential skill - it helps catch problems early and improves the quality of the shared work.
-
Find a PR to review. Click on the tab
Pull requestsin the top navigation of the repository. Look for a PR where a classmate has requested your review. Otherwise, pick one that has not been reviewed yet. -
Read the description. Before looking at the code, read the top comment, written by the creator of the PR. You can find it under the tab
Conversation. Understand what the author intended to change and why. If there is an issue linked to the PR, read it to get more context. -
Review the changes. Click on the
Files changedtab to see the diff. Lines in green (with a+) are additions; lines in red (with a-) are deletions. -
Leave an inline comment. Hover over a line you want to comment on. Click the blue ➕ icon that appears to the left of the line. You can also select multiple lines, if needed. Type your comment in the box that appears. It’s best to click
Start a review, instead ofAdd single comment, in case you want to add more comments before submitting the review. -
Make an inline suggestion. While writing a comment, click the
±icon in the toolbar. GitHub will insert the selected line(s) into a code block. Edit those directly to propose a concrete change. The author can then accept your suggestion with a single click. -
Submit your review. When you have finished adding comments, click the green
Submit reviewbutton at the top-right of the diff view page.- Write a brief overall summary comment.
- Choose one of the three options:
- Approve - the PR looks good as is.
- Comment - you have feedback, but it is not blocking.
- Request changes - something must be fixed before this can be merged.
- Click the green
Submit reviewbutton.
7. Merge Your Pull Request
Section titled “7. Merge Your Pull Request”Once your reviewer has approved your pull request, you can merge your branch into main.
-
Open your pull request. Go to the
Pull requeststab and click on your PR. -
Check the review status. If your reviewer requested changes, address the feedback first:
- To accept an inline suggestion, click the green
Apply suggestionbutton directly on the comment. - To make other changes, go to your branch, edit the file, and commit again. The PR updates automatically.
- Once you have addressed everything, click the green
Re-request reviewbutton to notify your reviewer.
- To accept an inline suggestion, click the green
-
Resolve conversations. After addressing feedback, mark each comment thread as
Resolved. -
Merge the pull request. When the PR is approved, click the green
Merge pull requestbutton. Confirm by clickingConfirm merge. -
Delete the branch. After merging, GitHub shows a button to
Delete branch. Click it, then the branch has served its purpose and can be deleted. -
Check that your issue is closed. Go to the
Issuestab. Because you wroteCloses #7in the PR description, the issue should now be automatically closed. -
View the network graph. Go to the
Insights > Networktab again. You will now see your branch joining themainline - a visual record of your contribution.
8. Resolve a Conflict
Section titled “8. Resolve a Conflict”A merge conflict occurs when two branches have changed the same part of the same file in different ways. Git cannot decide which version to keep automatically so it needs a human to choose.
How a conflict happens
Section titled “How a conflict happens”Imagine two people both edit README.md on their respective branches:
- Branch A changes the project title to
"Empa Git Workshop". - Branch B changes the same line to
"Empa GitHub Tutorial".
When Branch A is merged first, Branch B now conflicts with main.
Resolve the conflict in the GitHub web interface
Section titled “Resolve the conflict in the GitHub web interface”-
Open the conflicting pull request. Go to the
Pull requeststab and open the PR that shows a conflict. You will see a warning banner: “This branch has conflicts that must be resolved”. -
Click Resolve conflicts. GitHub will open an inline editor showing the conflict markers.
-
Understand the conflict markers. The file will look something like this:
<<<<<<< your-branchEmpa GitHub Tutorial=======Empa Git Workshop>>>>>>> main- Everything between
<<<<<<< your-branchand=======is the version fromyour-branch. - Everything between
=======and>>>>>>> mainis the version frommain.
- Everything between
-
Choose the correct version. Edit the file directly in the browser:
- Delete the conflict markers (
<<<<<<<,=======,>>>>>>>). - Keep the text you want (either one version, the other, or a combination).
For example, after resolving:
Empa Git Workshop & Tutorial - Delete the conflict markers (
-
Mark as resolved. Once you have edited all conflicts in the file, click the
Mark as resolvedbutton. If there are conflicts in multiple files, repeat the process for each one. -
Commit the merge. After all conflicts are resolved, click the green
Commit mergebutton. GitHub will create a special merge commit that records how the conflict was resolved. -
Merge the pull request. The conflict warning is gone. Click
Merge pull request>Confirm mergeto complete the process.