diff --git a/.DS_Store b/.DS_Store index 3d5c4e3..d3b50cf 100644 Binary files a/.DS_Store and b/.DS_Store differ diff --git a/presentation/.DS_Store b/presentation/.DS_Store new file mode 100644 index 0000000..423f810 Binary files /dev/null and b/presentation/.DS_Store differ diff --git a/presentation/Intro_To_Git.html b/presentation/Intro_To_Git.html new file mode 100644 index 0000000..bae6c89 --- /dev/null +++ b/presentation/Intro_To_Git.html @@ -0,0 +1,1323 @@ + + + + + + + + + + + + + + Git for beginners + + + + + + + + + + + + + + + +
+
+ +
+

Git for beginners

+

or how I learned to stop worrying and love version control

+ +
+
+
+James Emberton, Amy Pike and Marion Weinzierl +
+
+
+ +
+
+

+
+Learning Outcomes +
+
+
    +
  • Be familiar with the building blocks of git: repositories, commits and branches
  • +
  • Get started with using git locally on your own projects
  • +
  • Get started with collaborating on code projects using GitHub
  • +
  • Gain an appreciation for how useful git can be
  • +
+
+
+
+

+
+First! A few questions about Git and Github +
+
+
    +
  • Who has used any sort of code version control before?
  • +
  • Who has used Git or Github
  • +
  • Who wants to do better version control in their projects?
  • +
+
+
+
+
+
+
+
+ +
+

Version Control

+
+
+

Tools like Git and Github exist as solutions to the problem of how to save, share, and collaborate in a structured and safe way.

+

Useful whether you are working alone or in a team!

+
+
+
+
+
+
+
+

+
+Why Git? +
+
+
    +
  • Distributed version control
  • +
  • Lightweight but powerful branching and merging
  • +
  • High performance/Scalable
  • +
  • Excellent data integrity protection
  • +
  • Open source with a rich ecosystem, flexible and customisable
  • +
  • Fine grained control over committing, viewing history and reverting
  • +
+
+
+
+

+
+In today's course we will: +
+
    +
  • Create a local git repository
  • +
  • Create a git commit in your repository
  • +
  • Create a git branch in your repository
  • +
  • Fork a remote repository and check it out on your local machine
  • +
+
+
+

+
+What is a Git repository? +
+
    +
  • A place where you can store your code, your files, and each file’s revision history.
  • +
  • Contains a .git folder at the root which does all the git magic behind the scenes.
  • +
+
+
+

+
+Exercise 1, creating a git repository: +
- Navigate to a folder you want to work in, and create a new folder to contain your repository: +
+
+

+$ cd your_dir
+$ mkdir your_folder
+$ cd your_folder
+
+
+Then initialise the folder +
+

+$ git init
+
+
+
+
+
+
+
+ +
+

.git

+
+
+

A hidden “.git” folder has been created in your folder. This contains everything Git needs to work.

+
+
+
+
+
+
+

+
+What is a Git commit? +
+
    +
  • You can think of a commit as a snapshot of your work at a particular time
  • +
  • You can navigate between commits easily with git
  • +
  • This allows you to switch easily between different versions of your work
  • +
  • When you commit, rather than saving all the files in a project every time, git is efficient and only stores the files which have been changed between the previous commit and your current one
  • +
  • The commit also stores a reference to its parent commit
  • +
+
+
+

+
+Commiting is a three part process: +
+
    +
  1. Modify: change the file in your working tree, ie go in and edit the file as usual
  2. +
  3. Stage: Tell git that you would like this file to be included in your next commit
  4. +
  5. Commit: Tell git to take a snapshot of the files you staged
  6. +
+
+
+

+
+At each step in the process, the file is stored in a different area: +
+ +
+
+

+
+This means that Git has four main states that your files can be in: +
+
    +
  • Untracked: You’ve created a new file and not told git to keep track of it.
  • +
  • Modified: You’ve changed a file that git already has a record of, but have not told git to include these changes in your next commit. We say these files are in the working tree.
  • +
  • Staged: You’ve told git to include the file next time you do a commit. We say these files are in the staging area.
  • +
  • Committed: The file is saved in it’s present state in the most recent commit.
  • +
+
+
+

+
+Exercise 2a, create an untracked file: +
+ +
+
+

+
+Exercise 2a, create an untracked file: +
- Create a new file in your repository. +
+
+

+$ touch new.txt
+$ code new.txt
+
+
+
Lets check what git can see… +
+

+$ git status
+
+
+
+
+

+
+

+$ git status
+
+On branch main
+
+No commits yet
+
+Untracked files:
+   (use "git add ..." to include in what will be committed)
+
+    new.txt
+
+nothing added to commit but untracked files present (use "git add" to track)
+
+
+
+
+
+
+
+ +
+

git status

+
+
+

Highlights your working branch -> main
Reports commit status -> none yet
Highlights untracked files -> new.txt
Proposes adding these to git with ‘git add’

+
+
+
+
+
+
+

+
+Exercise 2b, add the untracked file to the staging area: +
+ +
+
+

+
+Exercise 2b, add the untracked file to the staging area: +
Try these commands... +
+
+

+$ git add .
+
+
+
+
+

+$ git status
+
+
+
+
+
+

+
+

+$ git status
+
+On branch main
+
+No commits yet
+
+Changes to be committed:
+  (use "git rm --cached ..." to unstage)
+
+    new file:   new.txt
+
+
+
+
+
+
+
+
+ +
+

git add

+
+
+

Moves file(s) into “Staging area” ready for commit

+
+
+
+
+
+
+

+
+Exercise 2c, commiting your changes: +
+ +
+
+

+
+Exercise 2c, commiting your changes: +
- Commit your file to the local git repo +
+
+

+$ git commit -m "Created new.txt"
+
+
+
+

‘git commit’ >>>> tells git you want to commit

‘-m “Comment”’ >>>> adds a description to the log for this commit. This is important as it tells you and others what the commit intent is.

+
+
+

+
+

+$ git commit -m "Created new.txt"
+
+[main (root-commit) f22b25e] Created new.txt
+ 1 file changed, 1 insertion(+)
+ create mode 100644 new.txt
+
+
+
+
+

+$ git status
+
+On branch main
+nothing to commit, working tree clean
+
+
+
+
+
+

+
+

+$ git log
+
+commit f22b25e3233b4645dabd0d81e651fe074bd8e73b
+Author: James Emberton 
+Date:   Tues May 27 09:51:46 2024 -0400
+
+    Create new.txt
+
+
+
+
+
+
+
+
+ +
+

git log

+
+
+

Displays commits in reverse chronological order.

+

Includes full identifier, author and date

+
+
+
+
+
+
+

+
+What is a Git branch? +
+
    +
  • A branch is a pointer to a git commit
  • +
  • It says “I want to include the work of this commit and all of its parent commits.”
  • +
  • We can use the checkout command to switch between different branches and commits
  • +
+
+
+

+
+Exercise 3, creating a git branch, checking it out and commiting +
+ +
+
+

+
+Exercise 3, creating a git branch and checking it out +
+
    +
  • Create a new branch using: git branch my-shiny-new-branch

  • +
  • Checkout the branch using: git checkout my-shiny-new-branch

  • +
  • Make a change in your new branch by editing new.txt and committing the changes.

  • +
  • Note: you can combine the first two steps into one using git checkout -b my-shiny-new-branch

  • +
+
+
+

+
+Exercise 4, switching between branches +
+ +
+
+

+
+Exercise 4, switching between branches +
+
    +
  • return to the main branch using git checkout main

  • +
  • open the new.txt file, what’s inside?

  • +
  • make a new file, new_2.txt

  • +
  • commit this new file to the main branch

  • +
  • switch back to your other branch and inspect the files again

  • +
  • Note: you can use git checkout - as a shortcut for returning to the previous branch you checked out.

  • +
+
+
+

+
+Ways of working with a remote repository +
+
+

A remote repository is one stored in the cloud. We will be using GitHub to do this today.
+There are two different ways to copy a remote repository so that you can work on it locally:

+
+
    +
  • clone: This makes a copy locally which is closely linked to the remote version. Your local branches can be synced to branches in the original.
  • +
  • fork: This makes another separate version of the repo remotely that you own. Once you have forked a repo remotely, you can then clone it to your local machine. Branches created locally can’t be synced to branches in the original repo, they are synced to your forked repo instead. You can still open pull requests to the original if you would like to make a contribution to it.
  • +
+
+
+

+
+To clone or to fork? +
+

Use a clone when:

+
    +
  • You are collaborating directly and actively with the owner of the repo (e.g. it is your research team, or you) OR all of the following is true:

  • +
  • It is owned by someone else and you are happy not to have ownership of the codebase

  • +
  • You have permission to push branches up to the repo

  • +
  • You want easy access to the latest changes made by others to the central repository

  • +
  • You want the main branch in the repo to be updated and edited by others working on the project

  • +
+
+
+

+
+To clone or to fork? +
+

Use a fork when:

+
    +
  • The owner of the repo is not someone you are actively collaborating with
  • +
  • You want to take the development of the code in a different direction from the original owner of the repo
  • +
  • You want full ownership over your version of the codebase
  • +
  • You want complete control over other’s contributions to the codebase
  • +
  • You do not want the main branch to receive updates from those editing the existing repo
  • +
  • Or you do not have permission to push branches directly to the original repo
  • +
+
+
+

+
+Working with remote repositories +
+ +
+
+

+
+Exercise 5, forking a repo from GitHub +
+
+
+

+
+Collaborative git with GitHub +
+
+
+
+
+ +
+

Warning

+
+
+

You must have already created a github account and connected your local git repo to it before you can do these exercises

+
+
+
+

Navigate to https://github.com/Cambridge-ICCS and find the ‘git-intro-iccs-summer-school-2024’ repo

+

We will fork this repo, clone the fork to our local computers, make edits and then try merging these back into the original repo.

+
+
+

+
+Exercise 5: +
- From Github, Cambridge-ICCS/git-intro-iccs-summer-school-2024 +
+
+
+
+
+

+
Github Fork option
+
+
+
+
+
+

+
Fork menu
+
+
+
+
+
+
+

+
+Your forked repo only exists in Github. To work on it locally it needs to be copied to your local computer. +
+
+

+$ git clone https://github.com/YOUR-USERNAME/YOUR-REPOSITORY
+
+
+
+
+
+
+ +
+

Warning

+
+
+

Clone repo to a new working folder.

+

Do not clone into an existing local git repo.

+
+
+
+
+
    +
  • Choose/create a file to edit, and then commit.
    +
  • +
  • Next push the changes up to the remote repo.
    +
  • +
  • The first time you do this on a new branch, you will need to set up a remote one to track it:
    +
  • +
  • git push --set-upstream origin your-branch-name
    +
  • +
  • For any commits after that on the branch you can use git push on it’s own when you are on the branch you want to push.
  • +
+
+
+
+

+
+The final step is to put in a pull request (PR) to the original repo that we forked from. +
+A pull request is how we signal to the repo owner that we want to merge in our changes. + +
+ +
+Depending on the code and the repo, you may not be able to merge directly. +
Reviews by one or more developers who may suggest/require edits to you code +
Pass testing +
+
+
+

+
+Learning Outcomes +
+
+
    +
  • Be familiar with the building blocks of git: repositories, commits and branches
  • +
  • Get started with using git locally on your own projects
  • +
  • Get started with collaborating on code projects using GitHub
  • +
  • Gain an appreciation for how useful git can be
  • +
+
+
+
+

+
+Anything you'd like to revisit or build on from today? +
+

Please come and visit us at a code clinic.
+

+

Book a slot in our “ICCS Summer School Code Clinic spreadsheet”, which is linked in the online agenda here:
+

+

https://cambridge-iccs.github.io/summerschool24
+

+

This course and the intermediate git course will also be made available on YouTube.

+

This is also a nice visual resource for learning git:
+

+

https://learngitbranching.js.org/

+
+ +
+
+
+
+ + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/presentation/Intro_To_Git.qmd b/presentation/Intro_To_Git.qmd index 47ba991..e913907 100644 --- a/presentation/Intro_To_Git.qmd +++ b/presentation/Intro_To_Git.qmd @@ -1,21 +1,37 @@ --- -title: "Git for beginners" -subtitle: "... *or how I learned to stop worrying and love version control*" -author: "James Emberton, Amy Pike and Marion Weinzierl" -format: - revealjs: - title-slide-attributes: - data-background-image: ../images/ICCS_title_slide.png - incremental: true - auto-stretch: true - data-background-image: ../images/ICCS_content_slide.png - smaller: true +output-file: index +title: Introduction to git and GitHub +authors: + - name: James Emberton + affiliations: ICCS - University of Cambridge + - name: Amy Pike + affiliations: ICCS - University of Cambridge + - name: Marion Weinzerl + affiliations: ICCS - University of Cambridge + +format: + revealjs: + title-slide-attributes: + data-background-image: images/ICCS_title_slide.png + theme: custom_theme.scss + embed-resources: false + incremental: true + history: false + smaller: true + highlight-style: a11y + code-line-numbers: false + scrollable: false + auto-stretch: false + # parallax-background-image: images/ICCS_content_slide.png + # parallax-background-size: 110% + # parallax-background-horizontal: 0 + # margin: 0.25 + logo: https://iccs.cam.ac.uk/sites/iccs.cam.ac.uk/files/iccs_ucam_combined_reverse_colour.png +jupyter: python3 --- -## {data-background-image=../images/ICCS_content_slide.png} -
-Learning Outcomes -
+## Learning Outcomes + ::: {.incremental} - Be familiar with the building blocks of git: repositories, commits and branches - Get started with using git locally on your own projects @@ -23,11 +39,8 @@ Learning Outcomes - Gain an appreciation for how useful git can be ::: -## {data-background-image=../images/ICCS_content_slide.png} +## First! A few questions about Git and Github -
-First! A few questions about Git and Github -
::: {.incremental} - Who has used any sort of code version control before? - Who has used Git or Github @@ -42,11 +55,9 @@ Tools like Git and Github exist as solutions to the problem of how to save, shar Useful whether you are working alone or in a team! ::: ::: -## {data-background-image=../images/ICCS_content_slide.png} -
-Why Git? -
+## Why Git? + ::: {.incremental} - Distributed version control - Lightweight but powerful branching and merging @@ -56,28 +67,21 @@ Why Git? - Fine grained control over committing, viewing history and reverting ::: -## {data-background-image=../images/ICCS_content_slide.png} -
-In today's course we will: -
+## In today's course we will: + - Create a local git repository - Create a git commit in your repository - Create a git branch in your repository - Fork a remote repository and check it out on your local machine +- Put in a PR to have our changes merged back to the remote repo -## {data-background-image=../images/ICCS_content_slide.png} -
-What is a Git repository? -
+## What is a Git repository? - A place where you can store your code, your files, and each file's revision history. - Contains a .git folder at the root which does all the git magic behind the scenes. -## {data-background-image=../images/ICCS_content_slide.png} - -
-Exercise 1, creating a git repository: +## Exercise 1, creating a git repository:
- Navigate to a folder you want to work in, and create a new folder to contain your repository: -
+

 $ cd your_dir
@@ -95,11 +99,7 @@ $ git init
 A hidden ".git" folder has been created in your folder. This contains everything Git needs to work.
 :::
 
-## {data-background-image=../images/ICCS_content_slide.png}
-
-
-What is a Git commit? -
+## What is a Git commit? - You can think of a commit as a snapshot of your work at a particular time - You can navigate between commits easily with git - This allows you to switch easily between different versions of your work @@ -107,27 +107,20 @@ What is a Git commit? and only stores the files which have been changed between the previous commit and your current one - The commit also stores a reference to its parent commit -## {data-background-image=../images/ICCS_content_slide.png} +## Commiting is a three part process: -
-Commiting is a three part process: -
1. Modify: change the file in your working tree, ie go in and edit the file as usual 2. Stage: Tell git that you would like this file to be included in your next commit 3. Commit: Tell git to take a snapshot of the files you staged -## {data-background-image=../images/ICCS_content_slide.png} +## At each step in the process, the file is stored in a different area: -
-At each step in the process, the file is stored in a different area: -
-![](../images/show_different_file_states.png) +![](images/show_different_file_states.png) -## {data-background-image=../images/ICCS_content_slide.png} +## git commit -
This means that Git has four main states that your files can be in: -
+ - Untracked: You've created a new file and not told git to keep track of it. - Modified: You've changed a file that git already has a record of, but have not told git to include these changes in your next commit. @@ -136,19 +129,12 @@ We say these files are in the working tree. We say these files are in the staging area. - Committed: The file is saved in it's present state in the most recent commit. -## {data-background-image=../images/ICCS_content_slide.png} +## Exercise 2a, create an untracked file: -
-Exercise 2a, create an untracked file: -
-![](../images/create_untracked_file.png) +![](images/create_untracked_file.png) -## {data-background-image=../images/ICCS_content_slide.png} - -
-Exercise 2a, create an untracked file: +## Exercise 2a, create an untracked file:
- Create a new file in your repository. -

@@ -164,7 +150,7 @@ $ git status
 
-## {data-background-image=../images/ICCS_content_slide.png} +## git status

 $ git status
@@ -189,33 +175,25 @@ Highlights your working branch -> main
 
Proposes adding these to git with 'git add' ::: -## {data-background-image=../images/ICCS_content_slide.png} +## Exercise 2b, add the untracked file to the staging area: -
-Exercise 2b, add the untracked file to the staging area: -
-![](../images/add_to_staging_area.png) +![](images/add_to_staging_area.png) -## {data-background-image=../images/ICCS_content_slide.png} +## Exercise 2b, add the untracked file to the staging area: -
-Exercise 2b, add the untracked file to the staging area:
Try these commands... -

 $ git add .
 
-

 $ git status
-
 
-## {data-background-image=../images/ICCS_content_slide.png} +## git add

@@ -235,34 +213,27 @@ Changes to be committed:
 
 ::: {.callout-tip title="git add"}
 Moves file(s) into "Staging area" ready for commit
-
::: -## {data-background-image=../images/ICCS_content_slide.png} +## Exercise 2c, commiting your changes: -
-Exercise 2c, commiting your changes: -
-![](../images/commit_to_repository.png) +![](images/commit_to_repository.png) -## {data-background-image=../images/ICCS_content_slide.png} +## Exercise 2c, commiting your changes: -
-Exercise 2c, commiting your changes: -
- Commit your file to the local git repo -
-
+Commit your file to the local git repo +

 $ git commit -m "Created new.txt"
-
 
+
'git commit' >>>> tells git you want to commit

'-m "Comment"' >>>> adds a description to the log for this commit. This is important as it tells you and others what the commit intent is. -## {data-background-image=../images/ICCS_content_slide.png} +## git commit

@@ -285,8 +256,7 @@ nothing to commit, working tree clean
 
-## {data-background-image=../images/ICCS_content_slide.png} - +## git log

 $ git log
@@ -306,46 +276,31 @@ Displays commits in reverse chronological order.
 Includes full identifier, author and date
 :::
 
-## {data-background-image=../images/ICCS_content_slide.png}
+## What is a Git branch?
 
-
-What is a Git branch? -
- A branch is a pointer to a git commit - It says "I want to include the work of this commit and all of its parent commits." - We can use the `checkout` command to switch between different branches and commits -![](../images/git_branching_illustration.png) +![](images/git_branching_illustration.png) -## {data-background-image=../images/ICCS_content_slide.png} +## Exercise 3, creating a git branch: -
-Exercise 3, creating a git branch, checking it out and commiting -
-![](../images/creating_branch_and_checking_out.png) +![](images/creating_branch_and_checking_out.png){width=40%} -## {data-background-image=../images/ICCS_content_slide.png} +## Exercise 3, creating a git branch and checking it out -
-Exercise 3, creating a git branch and checking it out -
- Create a new branch using: `git branch my-shiny-new-branch` - Checkout the branch using: `git checkout my-shiny-new-branch` - Make a change in your new branch by editing new.txt and committing the changes. - Note: you can combine the first two steps into one using `git checkout -b my-shiny-new-branch` -## {data-background-image=../images/ICCS_content_slide.png} - -
-Exercise 4, switching between branches -
-![](../images/switching_between_branches.png) +## Exercise 4, switching between branches +
+![creating branch and checking out](images/creating_branch_and_checking_out.png){width=35%} -## {data-background-image=../images/ICCS_content_slide.png} +## Exercise 4, switching between branches -
-Exercise 4, switching between branches -
- return to the main branch using `git checkout main` - open the new.txt file, what's inside? - make a new file, `new_2.txt` @@ -354,28 +309,26 @@ Exercise 4, switching between branches - Note: you can use `git checkout -` as a shortcut for returning to the previous branch you checked out. -## {data-background-image=../images/ICCS_content_slide.png} +## Ways of working with a remote repository -
-Ways of working with a remote repository -
-
A remote repository is one stored in the cloud. We will be using GitHub to do this today. \ There are two different ways to copy a remote repository so that you can work on it locally: -
+
+
- clone: This makes a copy locally which is closely linked to the remote version. Your local branches can be synced to branches in the original. +
+
- fork: This makes another separate version of the repo remotely that you own. Once you have forked a repo remotely, you can then clone it to your local machine. +
+
Branches created locally can't be synced to branches in the original repo, they are synced to your forked repo instead. You can still open pull requests to the original if you would like to make a contribution to it. -## {data-background-image=../images/ICCS_content_slide.png} +## To clone or to fork? -
-To clone or to fork? -
Use a clone when: - You are collaborating directly and actively with the owner of the repo (e.g. it is your research team, or you) @@ -386,11 +339,8 @@ OR all of the following is true: - You want easy access to the latest changes made by others to the central repository - You want the main branch in the repo to be updated and edited by others working on the project -## {data-background-image=../images/ICCS_content_slide.png} +## To clone or to fork? -
-To clone or to fork? -
Use a fork when: - The owner of the repo is not someone you are actively collaborating with @@ -401,24 +351,11 @@ Use a fork when: - Or you do not have permission to push branches directly to the original repo -## {data-background-image=../images/ICCS_content_slide.png} - -
-Working with remote repositories -
-![](../images/fork_vs_clone.png) - -## {data-background-image=../images/ICCS_content_slide.png} - -
-Exercise 5, forking a repo from GitHub -
+## Working with remote repositories -## {data-background-image=../images/ICCS_content_slide.png} +![](images/fork_vs_clone.png){width=50%} -
-Collaborative git with GitHub -
+## Collaborative git with GitHub ::: {.callout-warning} You must have already created a github account and connected your local git repo to it before you can do these exercises @@ -428,29 +365,27 @@ Navigate to https://github.com/Cambridge-ICCS and find the 'git-intro-iccs-summe We will fork this repo, clone the fork to our local computers, make edits and then try merging these back into the original repo. -## {data-background-image=../images/ICCS_content_slide.png} +## Exercise 5: -
-Exercise 5:
- From Github, Cambridge-ICCS/git-intro-iccs-summer-school-2024 -
+ :::: {.columns} ::: {.column width="40%"} -![Github Fork option](../images/Github%20fork.png) +![Github Fork option](images/Github%20fork.png) ::: ::: {.column width="60%"} -![Fork menu](../images/Fork%20menu.png) +![Fork menu](images/Fork%20menu.png) ::: :::: -## {data-background-image=../images/ICCS_content_slide.png} -
+## Cloning from GitHub + Your forked repo only exists in Github. To work on it locally it needs to be copied to your local computer. -
+

@@ -472,24 +407,21 @@ Do not clone into an existing local git repo.
 - For any commits after that on the branch you can use `git push` on it's own when you are on the branch you want to push.
 :::
 
-## {data-background-image=../images/ICCS_content_slide.png}
-
+## Pull requests + The final step is to put in a pull request (PR) to the original repo that we forked from.
+
A pull request is how we signal to the repo owner that we want to merge in our changes. -
-
Depending on the code and the repo, you may not be able to merge directly. -
Reviews by one or more developers who may suggest/require edits to you code -
Pass testing -
+- Reviews by one or more developers who may suggest/require edits to you code +- Pass testing + + +## Learning Outcomes -## {data-background-image=../images/ICCS_content_slide.png} -
-Learning Outcomes -
::: {.incremental} - Be familiar with the building blocks of git: repositories, commits and branches - Get started with using git locally on your own projects @@ -497,10 +429,9 @@ Learning Outcomes - Gain an appreciation for how useful git can be ::: -## {data-background-image=../images/ICCS_content_slide.png} -
+## Final thoughts? Anything you'd like to revisit or build on from today? -
+ Please come and visit us at a code clinic. \ Book a slot in our "ICCS Summer School Code Clinic spreadsheet", diff --git a/presentation/custom_theme.scss b/presentation/custom_theme.scss new file mode 100644 index 0000000..8b6fbe8 --- /dev/null +++ b/presentation/custom_theme.scss @@ -0,0 +1,47 @@ + +/*-- scss:rules --*/ + +// title and headings + + + +#title-slide { + text-align: center; + + .title { + color: #fffae6; + font-weight: 350; + //line-height: 0; + } + + .subtitle { + color: #fffae6; + font-style: italic; + } + + .author, .quarto-title-author-name, .quarto-title-authors { + color: #fffae6; + font-size: 1.2em; + } + +} + +#title-slide .slide-logo{ + top: 200px; + background: #ffffff; +} + +/*-- vertically center columns (or any container) --*/ +.v-center-container { + display: flex; + justify-content: center; + align-items: center; + height: 90%; +} + +/*-- standard offset for text on content slides --*/ +.reveal .slides > section:not(#title-slide) { + padding-top: 50px; /* Adjust the value as needed */ +} + + diff --git a/image_src/Fork vs Clone.drawio b/presentation/image_src/Fork vs Clone.drawio similarity index 100% rename from image_src/Fork vs Clone.drawio rename to presentation/image_src/Fork vs Clone.drawio diff --git a/image_src/Staging area diagram.drawio b/presentation/image_src/Staging area diagram.drawio similarity index 100% rename from image_src/Staging area diagram.drawio rename to presentation/image_src/Staging area diagram.drawio diff --git a/image_src/commit_illustration_src.drawio b/presentation/image_src/commit_illustration_src.drawio similarity index 100% rename from image_src/commit_illustration_src.drawio rename to presentation/image_src/commit_illustration_src.drawio diff --git a/images/.DS_Store b/presentation/images/.DS_Store similarity index 100% rename from images/.DS_Store rename to presentation/images/.DS_Store diff --git a/images/Fork menu.png b/presentation/images/Fork menu.png similarity index 100% rename from images/Fork menu.png rename to presentation/images/Fork menu.png diff --git a/images/Github fork.png b/presentation/images/Github fork.png similarity index 100% rename from images/Github fork.png rename to presentation/images/Github fork.png diff --git a/images/ICCS_content_slide.png b/presentation/images/ICCS_content_slide.png similarity index 100% rename from images/ICCS_content_slide.png rename to presentation/images/ICCS_content_slide.png diff --git a/images/ICCS_title_slide.png b/presentation/images/ICCS_title_slide.png similarity index 100% rename from images/ICCS_title_slide.png rename to presentation/images/ICCS_title_slide.png diff --git a/images/add_to_staging_area.png b/presentation/images/add_to_staging_area.png similarity index 100% rename from images/add_to_staging_area.png rename to presentation/images/add_to_staging_area.png diff --git a/images/commit_to_repository.png b/presentation/images/commit_to_repository.png similarity index 100% rename from images/commit_to_repository.png rename to presentation/images/commit_to_repository.png diff --git a/images/create_untracked_file.png b/presentation/images/create_untracked_file.png similarity index 100% rename from images/create_untracked_file.png rename to presentation/images/create_untracked_file.png diff --git a/images/creating_branch_and_checking_out.png b/presentation/images/creating_branch_and_checking_out.png similarity index 100% rename from images/creating_branch_and_checking_out.png rename to presentation/images/creating_branch_and_checking_out.png diff --git a/images/fork_vs_clone.png b/presentation/images/fork_vs_clone.png similarity index 100% rename from images/fork_vs_clone.png rename to presentation/images/fork_vs_clone.png diff --git a/images/git.png b/presentation/images/git.png similarity index 100% rename from images/git.png rename to presentation/images/git.png diff --git a/images/git_branching_illustration.png b/presentation/images/git_branching_illustration.png similarity index 100% rename from images/git_branching_illustration.png rename to presentation/images/git_branching_illustration.png diff --git a/images/git_commit_2x.png b/presentation/images/git_commit_2x.png similarity index 100% rename from images/git_commit_2x.png rename to presentation/images/git_commit_2x.png diff --git a/images/show_different_file_states.png b/presentation/images/show_different_file_states.png similarity index 100% rename from images/show_different_file_states.png rename to presentation/images/show_different_file_states.png diff --git a/images/switching_between_branches.png b/presentation/images/switching_between_branches.png similarity index 100% rename from images/switching_between_branches.png rename to presentation/images/switching_between_branches.png diff --git a/presentation/index.html b/presentation/index.html new file mode 100644 index 0000000..38042fc --- /dev/null +++ b/presentation/index.html @@ -0,0 +1,1231 @@ + + + + + + + + + + + + + Introduction to git and GitHub + + + + + + + + + + + + + + + +
+
+ +
+

Introduction to git and GitHub

+ +
+
+
+James Emberton +
+

+ ICCS - University of Cambridge +

+
+
+
+Amy Pike +
+

+ ICCS - University of Cambridge +

+
+
+
+Marion Weinzerl +
+

+ ICCS - University of Cambridge +

+
+
+ +
+
+

Learning Outcomes

+
+
    +
  • Be familiar with the building blocks of git: repositories, commits and branches
  • +
  • Get started with using git locally on your own projects
  • +
  • Get started with collaborating on code projects using GitHub
  • +
  • Gain an appreciation for how useful git can be
  • +
+
+
+
+

First! A few questions about Git and Github

+
+
    +
  • Who has used any sort of code version control before?
  • +
  • Who has used Git or Github
  • +
  • Who wants to do better version control in their projects?
  • +
+
+
+
+
+
+
+
+ +
+

Version Control

+
+
+

Tools like Git and Github exist as solutions to the problem of how to save, share, and collaborate in a structured and safe way.

+

Useful whether you are working alone or in a team!

+
+
+
+
+
+
+
+

Why Git?

+
+
    +
  • Distributed version control
  • +
  • Lightweight but powerful branching and merging
  • +
  • High performance/Scalable
  • +
  • Excellent data integrity protection
  • +
  • Open source with a rich ecosystem, flexible and customisable
  • +
  • Fine grained control over committing, viewing history and reverting
  • +
+
+
+
+

In today’s course we will:

+
    +
  • Create a local git repository
  • +
  • Create a git commit in your repository
  • +
  • Create a git branch in your repository
  • +
  • Fork a remote repository and check it out on your local machine
  • +
  • Put in a PR to have our changes merged back to the remote repo
  • +
+
+
+

What is a Git repository?

+
    +
  • A place where you can store your code, your files, and each file’s revision history.
  • +
  • Contains a .git folder at the root which does all the git magic behind the scenes.
  • +
+
+
+

Exercise 1, creating a git repository:

+


- Navigate to a folder you want to work in, and create a new folder to contain your repository:

+
+

+$ cd your_dir
+$ mkdir your_folder
+$ cd your_folder
+
+
+Then initialise the folder +
+

+$ git init
+
+
+
+
+
+
+
+ +
+

.git

+
+
+

A hidden “.git” folder has been created in your folder. This contains everything Git needs to work.

+
+
+
+
+
+
+

What is a Git commit?

+
    +
  • You can think of a commit as a snapshot of your work at a particular time
  • +
  • You can navigate between commits easily with git
  • +
  • This allows you to switch easily between different versions of your work
  • +
  • When you commit, rather than saving all the files in a project every time, git is efficient and only stores the files which have been changed between the previous commit and your current one
  • +
  • The commit also stores a reference to its parent commit
  • +
+
+
+

Commiting is a three part process:

+
    +
  1. Modify: change the file in your working tree, ie go in and edit the file as usual
  2. +
  3. Stage: Tell git that you would like this file to be included in your next commit
  4. +
  5. Commit: Tell git to take a snapshot of the files you staged
  6. +
+
+
+

At each step in the process, the file is stored in a different area:

+

+
+
+

git commit

+

This means that Git has four main states that your files can be in:

+
    +
  • Untracked: You’ve created a new file and not told git to keep track of it.
  • +
  • Modified: You’ve changed a file that git already has a record of, but have not told git to include these changes in your next commit. We say these files are in the working tree.
  • +
  • Staged: You’ve told git to include the file next time you do a commit. We say these files are in the staging area.
  • +
  • Committed: The file is saved in it’s present state in the most recent commit.
  • +
+
+
+

Exercise 2a, create an untracked file:

+

+
+
+

Exercise 2a, create an untracked file:

+


- Create a new file in your repository.

+
+

+$ touch new.txt
+$ code new.txt
+
+
+
Lets check what git can see… +
+

+$ git status
+
+
+
+
+

git status

+
+

+$ git status
+
+On branch main
+
+No commits yet
+
+Untracked files:
+   (use "git add ..." to include in what will be committed)
+
+    new.txt
+
+nothing added to commit but untracked files present (use "git add" to track)
+
+
+
+
+
+
+
+ +
+

git status

+
+
+

Highlights your working branch -> main
Reports commit status -> none yet
Highlights untracked files -> new.txt
Proposes adding these to git with ‘git add’

+
+
+
+
+
+
+

Exercise 2b, add the untracked file to the staging area:

+

+
+
+

Exercise 2b, add the untracked file to the staging area:

+
Try these commands… +
+

+$ git add .
+
+
+
+

+$ git status
+
+
+
+
+

git add

+
+

+$ git status
+
+On branch main
+
+No commits yet
+
+Changes to be committed:
+  (use "git rm --cached ..." to unstage)
+
+    new file:   new.txt
+
+
+
+
+
+
+
+
+ +
+

git add

+
+
+

Moves file(s) into “Staging area” ready for commit

+
+
+
+
+
+
+

Exercise 2c, commiting your changes:

+

+
+
+

Exercise 2c, commiting your changes:

+
    +
  • Commit your file to the local git repo +
    +
    
    +$ git commit -m "Created new.txt"
    +
    +
  • +
+


‘git commit’ >>>> tells git you want to commit

‘-m “Comment”’ >>>> adds a description to the log for this commit. This is important as it tells you and others what the commit intent is.

+
+
+

git commit

+
+

+$ git commit -m "Created new.txt"
+
+[main (root-commit) f22b25e] Created new.txt
+ 1 file changed, 1 insertion(+)
+ create mode 100644 new.txt
+
+
+
+
+

+$ git status
+
+On branch main
+nothing to commit, working tree clean
+
+
+
+
+
+

git log

+
+

+$ git log
+
+commit f22b25e3233b4645dabd0d81e651fe074bd8e73b
+Author: James Emberton 
+Date:   Tues May 27 09:51:46 2024 -0400
+
+    Create new.txt
+
+
+
+
+
+
+
+
+ +
+

git log

+
+
+

Displays commits in reverse chronological order.

+

Includes full identifier, author and date

+
+
+
+
+
+
+

What is a Git branch?

+
    +
  • A branch is a pointer to a git commit
  • +
  • It says “I want to include the work of this commit and all of its parent commits.”
  • +
  • We can use the checkout command to switch between different branches and commits
  • +
+
+
+

Exercise 3, creating a git branch:

+

+
+
+

Exercise 3, creating a git branch and checking it out

+
    +
  • Create a new branch using: git branch my-shiny-new-branch

  • +
  • Checkout the branch using: git checkout my-shiny-new-branch

  • +
  • Make a change in your new branch by editing new.txt and committing the changes.

  • +
  • Note: you can combine the first two steps into one using git checkout -b my-shiny-new-branch

  • +
+
+
+

Exercise 4, switching between branches

+


creating branch and checking out

+
+
+

Exercise 4, switching between branches

+
    +
  • return to the main branch using git checkout main

  • +
  • open the new.txt file, what’s inside?

  • +
  • make a new file, new_2.txt

  • +
  • commit this new file to the main branch

  • +
  • switch back to your other branch and inspect the files again

  • +
  • Note: you can use git checkout - as a shortcut for returning to the previous branch you checked out.

  • +
+
+
+

Ways of working with a remote repository

+

A remote repository is one stored in the cloud. We will be using GitHub to do this today.
+There are two different ways to copy a remote repository so that you can work on it locally:

- clone: This makes a copy locally which is closely linked to the remote version. Your local branches can be synced to branches in the original.

- fork: This makes another separate version of the repo remotely that you own. Once you have forked a repo remotely, you can then clone it to your local machine.

Branches created locally can’t be synced to branches in the original repo, they are synced to your forked repo instead. You can still open pull requests to the original if you would like to make a contribution to it.

+
+
+

To clone or to fork?

+

Use a clone when:

+
    +
  • You are collaborating directly and actively with the owner of the repo (e.g. it is your research team, or you) OR all of the following is true:

  • +
  • It is owned by someone else and you are happy not to have ownership of the codebase

  • +
  • You have permission to push branches up to the repo

  • +
  • You want easy access to the latest changes made by others to the central repository

  • +
  • You want the main branch in the repo to be updated and edited by others working on the project

  • +
+
+
+

To clone or to fork?

+

Use a fork when:

+
    +
  • The owner of the repo is not someone you are actively collaborating with
  • +
  • You want to take the development of the code in a different direction from the original owner of the repo
  • +
  • You want full ownership over your version of the codebase
  • +
  • You want complete control over other’s contributions to the codebase
  • +
  • You do not want the main branch to receive updates from those editing the existing repo
  • +
  • Or you do not have permission to push branches directly to the original repo
  • +
+
+
+

Working with remote repositories

+

+
+
+

Collaborative git with GitHub

+
+
+
+
+ +
+

Warning

+
+
+

You must have already created a github account and connected your local git repo to it before you can do these exercises

+
+
+
+

Navigate to https://github.com/Cambridge-ICCS and find the ‘git-intro-iccs-summer-school-2024’ repo

+

We will fork this repo, clone the fork to our local computers, make edits and then try merging these back into the original repo.

+
+
+

Exercise 5:

+


- From Github, Cambridge-ICCS/git-intro-iccs-summer-school-2024

+
+
+
+
+

+
Github Fork option
+
+
+
+
+
+

+
Fork menu
+
+
+
+
+
+
+

Cloning from GitHub

+

Your forked repo only exists in Github. To work on it locally it needs to be copied to your local computer.

+
+

+$ git clone https://github.com/YOUR-USERNAME/YOUR-REPOSITORY
+
+
+
+
+
+
+ +
+

Warning

+
+
+

Clone repo to a new working folder.

+

Do not clone into an existing local git repo.

+
+
+
+
+
    +
  • Choose/create a file to edit, and then commit.
    +
  • +
  • Next push the changes up to the remote repo.
    +
  • +
  • The first time you do this on a new branch, you will need to set up a remote one to track it:
    +
  • +
  • git push --set-upstream origin your-branch-name
    +
  • +
  • For any commits after that on the branch you can use git push on it’s own when you are on the branch you want to push.
  • +
+
+
+
+

Pull requests

+

The final step is to put in a pull request (PR) to the original repo that we forked from.

A pull request is how we signal to the repo owner that we want to merge in our changes.

Depending on the code and the repo, you may not be able to merge directly. - Reviews by one or more developers who may suggest/require edits to you code - Pass testing

+
+
+

Learning Outcomes

+
+
    +
  • Be familiar with the building blocks of git: repositories, commits and branches
  • +
  • Get started with using git locally on your own projects
  • +
  • Get started with collaborating on code projects using GitHub
  • +
  • Gain an appreciation for how useful git can be
  • +
+
+
+
+

Final thoughts?

+

Anything you’d like to revisit or build on from today?

+

Please come and visit us at a code clinic.
+

+

Book a slot in our “ICCS Summer School Code Clinic spreadsheet”, which is linked in the online agenda here:
+

+

https://cambridge-iccs.github.io/summerschool24
+

+

This course and the intermediate git course will also be made available on YouTube.

+

This is also a nice visual resource for learning git:
+

+

https://learngitbranching.js.org/

+
+

+ +
+
+
+
+ + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file