Work through a git tutorial on Windows10/11¶
Table of contents
1. First step : Understand the learning outcomes¶
In the communication Mattermost Chanel of FabLab sorbonne, our instructor shared 3 links:
- https://fabacademy.org/2022/labs/sorbonne/students/chloe-laurent/assignments/week02/
- https://rogerdudler.github.io/git-guide/index.fr.html
- https://www.youtube.com/watch?v=RGOj5yH7evk
I started by watching a video on git that Stephane shared with us. It was a 1-hour-long video! A few minutes later, I just give up the video and start from blank page to organize all my questions and answers about GIT. Hahahahahahaha, yes as you can guess, this decision took me more time and energy than watching the video for 1 hour. I asked many questions, searched on google, browsed others’s documentation in order to correct my answers and codes, until there is none error.
What are the tasks to achieve for the first week of Fab’Academy?
The assessment guide indicates the right path
- Communicate an initial project proposal = write down the first ideas of project that covers a large part of the Fab’Academy’s courses
- Identify and utilize version control protocol(s) = Learning how to use Git and GitLab
- Explore and use website development tool(s) = Learning how to use mkdocs + write contents for the documentation website
I don’t understand why do we need to use git and mkdocs to build a website, instead of ‘simply’ write html and css file to build the website?
If I only want to build a simple static website, knowing how to code in html and css is necessary. But in our context, Fab’Academy 2023, a static website is not sufficent. Because we want to update changes quickly, to be able to track the progress(even restore an older version of our website when a bug occurs), to have a main website that serve as archive for all student’s documentations on the same main repository gitlab, and to organize the order of presentations.(https://fabacademy.org/2023/) Think back to the first class I’ve took, this is the definition of version control. Now I understand better the concept. The next step is to learn how.
2. Using git, Clone and SSH Key¶
I observed that the main website of fab’Academy 2023 (https://fabacademy.org/2023/) correspond to the files in the git repository Fab Academy 2023 Site. To modify the content of the website, I suppose that we have to modify the files in the repository.
When I click on “clone”, there are 2 options for me to choose. “Clone” means a copy of a folder that can be synchronized with the repository via git.
Installation and configuration of GIT¶
To use git, we have to install it from https://git-scm.com/downloads
To configure git on Windows10/11:
git config --global user.name "First name Last name"
git config --global user.email “you@example.com”
Generate ssh key and clone¶
Open the repository git of your website, then click clone. You will find that there are two options: ssh and https. After few trial, I noticed that, we are able to push and pull unless we have a SSH key.
What are SSH keys?
Article : What are SSH Keys?
In simple words, SSH key is a pair of public and private key that are used for a more secure communication between our pc and the Fab’Academy git repository server.
How to genarate SSH Keys?
- Open git bash and copy
ssh-keygen
- Enter, and save the file
- Specify the password for SSH communication
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
- In file explorer, find the file that contains the key generated in the folder:
Windows(C:)>Users>yourname>.ssh
- Add the key to Gitlab
How to add the SSH Key generated?
- Sign in to GitLab.
- On the left sidebar, select your avatar.
- Select Edit profile.
- On the left sidebar, select SSH Keys.
- Select Key, and you should see the 1Password helper appear.
- Select the 1Password icon and unlock 1Password.
- You can then select Create SSH Key or select an existing SSH key to fill in the public key.
- In the Title box, type a description, like Work Laptop or Home Workstation.
- Optional. Select the Usage type of the key. It can be used either for Authentication or
- Signing or both. Authentication & Signing is the default value. Optional.
- Update Expiration date to modify the default expiration date.
- Select Add key.
Source: Article - Use SSH keys to communicate with GitLab
If you’re on Windows and a user of Medium:
Clone our own repository¶
I chose to create a new folder on the Desktop to save all the files related to the Fab’Academy 2023. I called it “A_FabAcademy”. As the name starts with an “A” it will be easier for me to find it.
In Git Bash, I opened the folder and clone my repository as follow:
Then cd into the folder, you will see (main) next to the path name.
Edit and make changes the files with mkdocs¶
See mkdocs’s documentation: doc_mkdocs.md
Update the changes: add-commit-push¶
Basic operations with GIT
git clone <the-repository-ssh-url>: download your repository from GitLab
git add: add the files and folders to upload
git commit: make changes in your repository
git push: update changes to your server repository.
git pull: get others modifications if you don’t have it yet (when collaborating with others working on the same repository)
After modifications, we would like to update our files to our directory git.
In git bash:
Ressource : Difference between Commit and Push
It’s nice to understand how to use GIT, and document the steps from cloning repo to pushing contents. Contents…But I don’t have any content right now. I don’t even know how to build a website with mkdocs, and how to use markdown.
Problem - Too much files: file size > 10Mb¶
In week 5, I’ve commited too much photos at the same time for push. The git repository refused to make the operation. Because she size of my commit was 12.7 Mb. I tried to find solutions to undo the changes. I tried “git reset –soft HEAD~ …”, but it deleted some changes I made on the website.
After doing some reseach on Google, I decided to do something I heard in class:
- Remove the current repository folder from my A_FabAcademy folder
- Clone a new git repository in the empty A_FabAcademy folder
- Make the necessary changes (copy the assignments markdown files that has been modified)
- Add the compressed photos and make sure the commit size does not exceed the 10 MB size limit.
- Then use this repository folder instead of the old one.
In the image below we can see the file size limits of Fab’Academy’s repo.