Overview
Teaching: 15 min
Exercises: 15 minQuestions
How do you get started with versioning using Git on the web?
Objectives
Creating repositories on GitHub
How to record (commit) changes
Browsing changes
Repository insights and settings
About this episode
We will practice creating a new repository using the web interface, committing changes to it, browsing the changes, creating branches, and more. This is everything you need to do basic file management, though you’ll probably want something faster to use. Still, it can be good for quick edits and contributions.
In smaller groups it can be useful to do this side by side (in-person) or one learner shares their screen (video) and others can ask questions and give suggestions. In a larger group the instructor can demonstrate these and then participants can try on their own and then ask questions.
Step 1: Create a repository with a README and a license
You start off by creating a repository on the web. In fact, we usually end up doing this on the web, no matter how you do your daily work. The important questions are who is the owner and what is the name of the repository.
Make sure that you are logged into GitHub.
To create a repository we either click the green button “New” (top left corner):
Or if you see your profile page, there is a “+” menu (top right corner):
Yet another way to create a new repository is to visit https://github.com/new Links to an external site. directly.
We then land at the following form. Please fill it out and set Initialize this repository with a README and choose a license. If you don’t find a suitable license, we will show later how you can add your own.
And now we have a repository with a README and LICENSE and one commit:
Step 2: Create a new file
We can easily add new files from the web interface.
Create a file, e.g. analysis.md
(the “md” ending signals that this is in Markdown format):
In the new file you can share a recipe – for example the necessary steps to run an analysis (or cooking or something else). You can also copy-paste this as a starting point:
Input files:
- samples_openrefine_lesson.csv -- the messy dataset from the OpenRefine lesson
- data_cleaning_script.txt -- the OpenRefine operations you've extracted
Output files:
- samples_openrefine_lesson_clean.csv -- the clean dataset reulting from the OpenRefine lesson
Instructions:
1. Start a new project in OpenRefine using the messy dataset you downloaded before (`samples_openrefine_lesson.csv`). Give the project a new name.
3. Click the `Undo / Redo` tab > `Apply` and paste in the contents of the data_cleaning_script.txt file you just created with the JSON code.
4. Click `Perform operations`. The dataset should now be the same as your other cleaned dataset.
Then add a commit message and commit (save):
Good commit messages
- What has changed is more useful than which file has changed
- Sometimes we forget to document why something was changed
- Many projects start out as projects “just for me” and end up to be successful projects that are developed by 50 people over decades.
- Write commit messages in English that will be understood 15 years from now by someone else than you.
- “My favourite Git commit” Links to an external site.
- “On commit messages” Links to an external site.
- “How to Write a Git Commit Message” Links to an external site.
Step 3: Modify a file
We can also easily modify files from the web.
Now improve the recipe by adding an ingredient or an instruction step:
- Click on the file.
- Click the “pen” icon on top right (“edit this file”).
Make an improvement, write a commit message, commit:
Once you have done that, browse your commits:
In my example I got:
Step 4: Create a new branch
A branch is a separate line of development. They are useful when you have multiple things going on at once and you don’t want them to get in the way of each other. It also allows collaboration, as we will learn in the next episode.
- Create a new branch:
- Modify your recipe on the newly created branch. Make sure you commit to the new branch:
- Then switch back to the
main
branch and browse your recipe there. Compare the file on both branches.
Step 5: Repository insights and settings
Github gives us many insights into our repository. Nothing here is really specific to Github (everything can be done with regular Git), but they make it especially easy to see. The network lets you see how all commits and branches relate.
Have a look at the network, hover over the dots in the graph (commits). The network view is the best way to get an overview of your branches and commits, and it never hurts to come back here and check:
Step 6: Adding a license to an existing repository
This is an optional step to show how we can add a license to an existing repository.
- Visit https://choosealicense.com/ Links to an external site. and let it guide you.
- If you don’t find a suitable license, choose among https://choosealicense.com/appendix/ Links to an external site..
- Once you have chosen, click on the license name, and you can enter your GitHub repository URL (top right) which will open a pull request (change request) to the repository:
Optional step: How can we merge branches?
This is an optional step which the instructor may demonstrate and discuss:
We made a separate branch, separate from the main branch main
.
What happens when we decide we like that change, and want to take it
into use? We will soon see the magic of Git.
First browse to the overview of all branches:
Now to initiate a merge (request), click on “New pull request”:
Once a “pull request” (think of it as a change proposal) is open, it can be reviewed and merged. We will return to “pull requests” when we later discuss how to contribute changes.