diff --git a/01-basics.md b/01-basics.md new file mode 100644 index 0000000..a03badf --- /dev/null +++ b/01-basics.md @@ -0,0 +1,141 @@ +--- +title: Automated Version Control +teaching: 5 +exercises: 0 +--- + +::::::::::::::::::::::::::::::::::::::: objectives + +- Understand the benefits of an automated version control system. +- Understand the basics of how automated version control systems work. + +:::::::::::::::::::::::::::::::::::::::::::::::::: + +:::::::::::::::::::::::::::::::::::::::: questions + +- What is version control and why should I use it? + +:::::::::::::::::::::::::::::::::::::::::::::::::: + +::::::::::::::::::::::::::::::::::::::::: instructor +Original lesson material: https://swcarpentry.github.io/git-novice/ +Slides: https://esciencecenter-digital-skills.github.io/digital-skills-slides/modules/git-lesson/git-slides, until https://esciencecenter-digital-skills.github.io/digital-skills-slides/modules/git-lesson/git-slides#/4. +Please note that slides will be deployed in the 'right place' in due time. Right now nobody knows where that is. + +The slides provide visual context to the concepts that are used in the live coding. It would be best to have both the live coding screen and the slides screen side by side. As this is in general not possible, it is best to switch back and forth between command line and slides when necessary (you can use the images in the teaching material as indication when to switch to the slides). + +Teach what you think is most useful. See how far you get, usually we get to episode 7 (Remotes in GitHub) in one morning. Ignore the temptation to answer advanced questions. (You can of course do this individually during exercises). + + +:::::::::::::::::::::::::::::::::::::::::::::::::: + +We'll start by exploring how version control can be used +to keep track of what one person did and when. +Even if you aren't collaborating with other people, +automated version control is much better than this situation: + +!["notFinal.doc" by Jorge Cham, ](fig/phd101212s.png){alt='Comic: a PhD student sends "FINAL.doc" to their supervisor, but after several increasingly intense and frustrating rounds of comments and revisions they end up with a file named "FINAL_rev.22.comments49.corrections.10.#@$%WHYDIDCOMETOGRADSCHOOL????.doc"'} + +We've all been in this situation before: it seems unnecessary to have +multiple nearly-identical versions of the same document. Some word +processors let us deal with this a little better, such as Microsoft +Word's +[Track Changes](https://support.office.com/en-us/article/Track-changes-in-Word-197ba630-0f5f-4a8e-9a77-3712475e806a), +Google Docs' [version history](https://support.google.com/docs/answer/190843?hl=en), or +LibreOffice's [Recording and Displaying Changes](https://help.libreoffice.org/Common/Recording_and_Displaying_Changes). + +Version control systems start with a base version of the document and +then record changes you make each step of the way. You can +think of it as a recording of your progress: you can rewind to start at the base +document and play back each change you made, eventually arriving at your +more recent version. + +![](fig/play-changes.svg){alt='Changes Are Saved Sequentially'} + +Once you think of changes as separate from the document itself, you +can then think about "playing back" different sets of changes on the base document, ultimately +resulting in different versions of that document. For example, two users can make independent +sets of changes on the same document. + +![](fig/versions.svg){alt='Different Versions Can be Saved'} + +Unless multiple users make changes to the same section of the document - a +[conflict](../learners/reference.md#conflict) - you can +incorporate two sets of changes into the same base document. + +![](fig/merge.svg){alt='Multiple Versions Can be Merged'} + +A version control system is a tool that keeps track of these changes for us, +effectively creating different versions of our files. It allows us to decide +which changes will be made to the next version (each record of these changes is +called a [commit](../learners/reference.md#commit)), and keeps useful metadata +about them. The complete history of commits for a particular project and their +metadata make up a [repository](../learners/reference.md#repository). +Repositories can be kept in sync across different computers, facilitating +collaboration among different people. + +::::::::::::::::::::::::::::::::::::::::: callout + +## The Long History of Version Control Systems + +Automated version control systems are nothing new. +Tools like [RCS](https://en.wikipedia.org/wiki/Revision_Control_System), [CVS](https://en.wikipedia.org/wiki/Concurrent_Versions_System), or [Subversion](https://en.wikipedia.org/wiki/Apache_Subversion) have been around since the early 1980s and are used by +many large companies. +However, many of these are now considered legacy systems (i.e., outdated) due to various +limitations in their capabilities. +More modern systems, such as Git and [Mercurial](https://swcarpentry.github.io/hg-novice/), +are *distributed*, meaning that they do not need a centralized server to host the repository. +These modern systems also include powerful merging tools that make it possible for +multiple authors to work on +the same files concurrently. + + +:::::::::::::::::::::::::::::::::::::::::::::::::: + +::::::::::::::::::::::::::::::::::::::: challenge + +## Paper Writing + +- Imagine you drafted an excellent paragraph for a paper you are writing, but later ruin + it. How would you retrieve the *excellent* version of your conclusion? Is it even possible? + +- Imagine you have 5 co-authors. How would you manage the changes and comments + they make to your paper? If you use LibreOffice Writer or Microsoft Word, what happens if + you accept changes made using the `Track Changes` option? Do you have a + history of those changes? + +::::::::::::::: solution + +## Solution + +- Recovering the excellent version is only possible if you created a copy + of the old version of the paper. The danger of losing good versions + often leads to the problematic workflow illustrated in the PhD Comics + cartoon at the top of this page. + +- Collaborative writing with traditional word processors is cumbersome. + Either every collaborator has to work on a document sequentially + (slowing down the process of writing), or you have to send out a + version to all collaborators and manually merge their comments into + your document. The 'track changes' or 'record changes' option can + highlight changes for you and simplifies merging, but as soon as you + accept changes you will lose their history. You will then no longer + know who suggested that change, why it was suggested, or when it was + merged into the rest of the document. Even online word processors like + Google Docs or Microsoft Office Online do not fully resolve these + problems. + + + +::::::::::::::::::::::::: + +:::::::::::::::::::::::::::::::::::::::::::::::::: + +:::::::::::::::::::::::::::::::::::::::: keypoints + +- Version control is like an unlimited 'undo'. +- Version control also allows many people to work in parallel. + +:::::::::::::::::::::::::::::::::::::::::::::::::: + + diff --git a/02-setup.md b/02-setup.md new file mode 100644 index 0000000..dffdbb3 --- /dev/null +++ b/02-setup.md @@ -0,0 +1,231 @@ +--- +title: Setting Up Git +teaching: 10 +exercises: 0 +--- + +::::::::::::::::::::::::::::::::::::::: objectives + +- Configure `git` the first time it is used on a computer. +- Understand the meaning of the `--global` configuration flag. + +:::::::::::::::::::::::::::::::::::::::::::::::::: + +:::::::::::::::::::::::::::::::::::::::: questions + +- How do I get set up to use Git? + +:::::::::::::::::::::::::::::::::::::::::::::::::: + +:::::::::::::::::::::::::::::::::::::::: instructor + +There are no slides for this episode. Explain what a command line is, why it is useful, and why we use it in this workshop. Participants are often new to the command line and don't get why we not use a git gui. Only focus on the bare essentials for setting up git. We shall use nano editor so that everyone is on the same page. + +:::::::::::::::::::::::::::::::::::::::::::::::::: + +When we use Git on a new computer for the first time, +we need to configure a few things. Below are a few examples +of configurations we will set as we get started with Git: + +- our name and email address, +- what our preferred text editor is, +- and that we want to use these settings globally (i.e. for every project). + +On a command line, Git commands are written as `git verb options`, +where `verb` is what we actually want to do and `options` is additional optional information which may be needed for the `verb`. So here is how +Dracula sets up his new laptop: + +```bash +$ git config --global user.name "Vlad Dracula" +$ git config --global user.email "vlad@tran.sylvan.ia" +``` + +Please use your own name and email address instead of Dracula's. This user name and email will be associated with your subsequent Git activity, +which means that any changes pushed to +[GitHub](https://github.com/), +[BitBucket](https://bitbucket.org/), +[GitLab](https://gitlab.com/) or +another Git host server +after this lesson will include this information. + +For this lesson, we will be interacting with [GitHub](https://github.com/) and so the email address used should be the same as the one used when setting up your GitHub account. If you are concerned about privacy, please review [GitHub's instructions for keeping your email address private][git-privacy]. + +::::::::::::::::::::::::::::::::::::::::: callout + +## Keeping your email private + +If you elect to use a private email address with GitHub, then use GitHub's no-reply email address for the `user.email` value. It looks like `ID+username@users.noreply.github.com`. You can look up your own address in your GitHub [email settings](https://github.com/settings/emails). + + +:::::::::::::::::::::::::::::::::::::::::::::::::: + +::::::::::::::::::::::::::::::::::::::::: callout + +## Line Endings + +As with other keys, when you hit Enter or or on Macs, Return on your keyboard, +your computer encodes this input as a character. +Different operating systems use different character(s) to represent the end of a line. +(You may also hear these referred to as newlines or line breaks.) +Because Git uses these characters to compare files, +it may cause unexpected issues when editing a file on different machines. +Though it is beyond the scope of this lesson, you can read more about this issue +[in the Pro Git book](https://www.git-scm.com/book/en/v2/Customizing-Git-Git-Configuration#_core_autocrlf). + +You can change the way Git recognizes and encodes line endings +using the `core.autocrlf` command to `git config`. +The following settings are recommended: + +On macOS and Linux: + +```bash +$ git config --global core.autocrlf input +``` + +And on Windows: + +```bash +$ git config --global core.autocrlf true +``` + +:::::::::::::::::::::::::::::::::::::::::::::::::: + +Dracula also has to set his favorite text editor, following this table: + +| Editor | Configuration command | +| :----------- | :------------------------------ | +| Atom | `$ git config --global core.editor "atom --wait"` | +| nano | `$ git config --global core.editor "nano -w"` | +| BBEdit (Mac, with command line tools) | `$ git config --global core.editor "bbedit -w"` | +| Sublime Text (Mac) | `$ git config --global core.editor "/Applications/Sublime\ Text.app/Contents/SharedSupport/bin/subl -n -w"` | +| Sublime Text (Win, 32-bit install) | `$ git config --global core.editor "'c:/program files (x86)/sublime text 3/sublime_text.exe' -w"` | +| Sublime Text (Win, 64-bit install) | `$ git config --global core.editor "'c:/program files/sublime text 3/sublime_text.exe' -w"` | +| Notepad (Win) | `$ git config --global core.editor "c:/Windows/System32/notepad.exe"` | +| Notepad++ (Win, 32-bit install) | `$ git config --global core.editor "'c:/program files (x86)/Notepad++/notepad++.exe' -multiInst -notabbar -nosession -noPlugin"` | +| Notepad++ (Win, 64-bit install) | `$ git config --global core.editor "'c:/program files/Notepad++/notepad++.exe' -multiInst -notabbar -nosession -noPlugin"` | +| Kate (Linux) | `$ git config --global core.editor "kate"` | +| Gedit (Linux) | `$ git config --global core.editor "gedit --wait --new-window"` | +| Scratch (Linux) | `$ git config --global core.editor "scratch-text-editor"` | +| Emacs | `$ git config --global core.editor "emacs"` | +| Vim | `$ git config --global core.editor "vim"` | +| VS Code | `$ git config --global core.editor "code --wait"` | + +It is possible to reconfigure the text editor for Git whenever you want to change it. + +::::::::::::::::::::::::::::::::::::::::: callout + +## Exiting Vim + +Note that Vim is the default editor for many programs. If you haven't used Vim before and wish to exit a session without saving +your changes, press Esc then type `:q!` and hit Enter or or on Macs, Return. +If you want to save your changes and quit, press Esc then type `:wq` and hit Enter or or on Macs, Return. + + +:::::::::::::::::::::::::::::::::::::::::::::::::: + +Git (2.28+) allows configuration of the name of the branch created when you +initialize any new repository. Dracula decides to use that feature to set it to `main` so +it matches the cloud service he will eventually use. + +```bash +$ git config --global init.defaultBranch main +``` + +::::::::::::::::::::::::::::::::::::::::: callout + +## Default Git branch naming + +Source file changes are associated with a "branch." +For new learners in this lesson, it's enough to know that branches exist, and this lesson uses one branch. +By default, Git will create a branch called `master` +when you create a new repository with `git init` (as explained in the next Episode). This term evokes +the racist practice of human slavery and the +[software development community](https://github.com/github/renaming) has moved to adopt +more inclusive language. + +In 2020, most Git code hosting services transitioned to using `main` as the default +branch. As an example, any new repository that is opened in GitHub and GitLab default +to `main`. However, Git has not yet made the same change. As a result, local repositories +must be manually configured have the same main branch name as most cloud services. + +For versions of Git prior to 2.28, the change can be made on an individual repository level. The +command for this is in the next episode. Note that if this value is unset in your local Git +configuration, the `init.defaultBranch` value defaults to `master`. + +:::::::::::::::::::::::::::::::::::::::::::::::::: + +The five commands we just ran above only need to be run once: the flag `--global` tells Git +to use the settings for every project, in your user account, on this computer. + +Let's review those settings and test our `core.editor` right away: + +```bash +$ git config --global --edit +``` + +Let's close the file without making any additional changes. Remember, since typos in the config file will cause +issues, it's safer to view the configuration with: + +```bash +$ git config --list +``` + +And if necessary, change your configuration using the +same commands to choose another editor or update your email address. +This can be done as many times as you want. + +::::::::::::::::::::::::::::::::::::::::: callout + +## Proxy + +In some networks you need to use a +[proxy](https://en.wikipedia.org/wiki/Proxy_server). If this is the case, you +may also need to tell Git about the proxy: + +```bash +$ git config --global http.proxy proxy-url +$ git config --global https.proxy proxy-url +``` + +To disable the proxy, use + +```bash +$ git config --global --unset http.proxy +$ git config --global --unset https.proxy +``` + +:::::::::::::::::::::::::::::::::::::::::::::::::: + +::::::::::::::::::::::::::::::::::::::::: callout + +## Git Help and Manual + +Always remember that if you forget the subcommands or options of a `git` command, you can access the +relevant list of options typing `git -h` or access the corresponding Git manual by typing +`git --help`, e.g.: + +```bash +$ git config -h +$ git config --help +``` + +While viewing the manual, remember the `:` is a prompt waiting for commands and you can press Q to exit the manual. + +More generally, you can get the list of available `git` commands and further resources of the Git manual typing: + +```bash +$ git help +``` + +:::::::::::::::::::::::::::::::::::::::::::::::::: + +[git-privacy]: https://help.github.com/articles/keeping-your-email-address-private/ + + +:::::::::::::::::::::::::::::::::::::::: keypoints + +- Use `git config` with the `--global` option to configure a user name, email address, editor, and other preferences once per machine. + +:::::::::::::::::::::::::::::::::::::::::::::::::: + + diff --git a/03-create.md b/03-create.md new file mode 100644 index 0000000..d54228a --- /dev/null +++ b/03-create.md @@ -0,0 +1,222 @@ +--- +title: Creating a Repository +teaching: 15 +exercises: 0 +--- + +::::::::::::::::::::::::::::::::::::::: objectives + +- Create a local Git repository. +- Describe the purpose of the `.git` directory. + +:::::::::::::::::::::::::::::::::::::::::::::::::: + +:::::::::::::::::::::::::::::::::::::::: questions + +- Where does Git store information? + +:::::::::::::::::::::::::::::::::::::::::::::::::: + +:::::::::::::::::::::::::::::::::::::::: instructor +Introduce here the story of Wolfman and Dracula. we all feel it is a bit silly example, but it suits the purpose. +Here we suggest referring to 'The Holy Realms of Git' slide: https://esciencecenter-digital-skills.github.io/digital-skills-slides/modules/git-lesson/git-slides#/5 to introduce the idea of repository and .git. + +:::::::::::::::::::::::::::::::::::::::::::::::::: + +Once Git is configured, we can start using it. + +We will continue with the story of Wolfman and Dracula who are investigating if it +is possible to send a planetary lander to Mars. + +![](fig/motivatingexample.png){alt='motivatingexample'} +[Werewolf vs dracula](https://www.deviantart.com/b-maze/art/Werewolf-vs-Dracula-124893530) +by [b-maze](https://www.deviantart.com/b-maze) / [Deviant Art](https://www.deviantart.com/). +[Mars](https://en.wikipedia.org/wiki/File:OSIRIS_Mars_true_color.jpg) by European Space Agency / +[CC-BY-SA 3.0 IGO](https://creativecommons.org/licenses/by/3.0/deed.en). +[Pluto](https://commons.wikimedia.org/wiki/File:PIA19873-Pluto-NewHorizons-FlyingPastImage-20150714-transparent.png) / +Courtesy NASA/JPL-Caltech. +[Mummy](https://commons.wikimedia.org/wiki/File:Mummy_icon_-_Noun_Project_4070.svg) +© Gilad Fried / [The Noun Project](https://thenounproject.com/) / +[CC BY 3.0](https://creativecommons.org/licenses/by/3.0/deed.en). +[Moon](https://commons.wikimedia.org/wiki/File:Lune_ico.png) +© Luc Viatour / [https://lucnix.be](https://lucnix.be/) / +[CC BY-SA 3.0](https://creativecommons.org/licenses/by-sa/3.0/deed.en). + +First, let's create a new directory in the `Desktop` folder for our work and then change the current working directory to the newly created one: + +```bash +$ cd ~/Desktop +$ mkdir planets +$ cd planets +``` + +Then we tell Git to make `planets` a [repository](../learners/reference.md#repository) +\-- a place where Git can store versions of our files: + +```bash +$ git init +``` + +It is important to note that `git init` will create a repository that +can include subdirectories and their files---there is no need to create +separate repositories nested within the `planets` repository, whether +subdirectories are present from the beginning or added later. Also, note +that the creation of the `planets` directory and its initialization as a +repository are completely separate processes. + +If we use `ls` to show the directory's contents, +it appears that nothing has changed: + +```bash +$ ls +``` + +But if we add the `-a` flag to show everything, +we can see that Git has created a hidden directory within `planets` called `.git`: + +```bash +$ ls -a +``` + +```output +. .. .git +``` + +Git uses this special subdirectory to store all the information about the project, +including the tracked files and sub-directories located within the project's directory. +If we ever delete the `.git` subdirectory, +we will lose the project's history. + +Next, we will change the default branch to be called `main`. +This might be the default branch depending on your settings and version +of git. +See the [setup episode](02-setup.md#default-git-branch-naming) for more information on this change. + +```bash +$ git switch -c main +``` + +```output +Switched to a new branch 'main' +``` + +We can check that everything is set up correctly +by asking Git to tell us the status of our project: + +```bash +$ git status +``` + +```output +On branch main + +No commits yet + +nothing to commit (create/copy files and use "git add" to track) +``` + +If you are using a different version of `git`, the exact +wording of the output might be slightly different. + +::::::::::::::::::::::::::::::::::::::: challenge + +## Places to Create Git Repositories + +Along with tracking information about planets (the project we have already created), +Dracula would also like to track information about moons. +Despite Wolfman's concerns, Dracula creates a `moons` project inside his `planets` +project with the following sequence of commands: + +```bash +$ cd ~/Desktop # return to Desktop directory +$ cd planets # go into planets directory, which is already a Git repository +$ ls -a # ensure the .git subdirectory is still present in the planets directory +$ mkdir moons # make a subdirectory planets/moons +$ cd moons # go into moons subdirectory +$ git init # make the moons subdirectory a Git repository +$ ls -a # ensure the .git subdirectory is present indicating we have created a new Git repository +``` + +Is the `git init` command, run inside the `moons` subdirectory, required for +tracking files stored in the `moons` subdirectory? + +::::::::::::::: solution + +## Solution + +No. Dracula does not need to make the `moons` subdirectory a Git repository +because the `planets` repository can track any files, sub-directories, and +subdirectory files under the `planets` directory. Thus, in order to track +all information about moons, Dracula only needed to add the `moons` subdirectory +to the `planets` directory. + +Additionally, Git repositories can interfere with each other if they are "nested": +the outer repository will try to version-control +the inner repository. Therefore, it's best to create each new Git +repository in a separate directory. To be sure that there is no conflicting +repository in the directory, check the output of `git status`. If it looks +like the following, you are good to go to create a new repository as shown +above: + +```bash +$ git status +``` + +```output +fatal: Not a git repository (or any of the parent directories): .git +``` + +::::::::::::::::::::::::: + +## Correcting `git init` Mistakes + +Wolfman explains to Dracula how a nested repository is redundant and may cause confusion +down the road. Dracula would like to remove the nested repository. How can Dracula undo +his last `git init` in the `moons` subdirectory? + +::::::::::::::: solution + +## Solution -- USE WITH CAUTION! + +### Background + +Removing files from a Git repository needs to be done with caution. But we have not learned +yet how to tell Git to track a particular file; we will learn this in the next episode. Files +that are not tracked by Git can easily be removed like any other "ordinary" files with + +```bash +$ rm filename +``` + +Similarly a directory can be removed using `rm -r dirname` or `rm -rf dirname`. +If the files or folder being removed in this fashion are tracked by Git, then their removal +becomes another change that we will need to track, as we will see in the next episode. + +### Solution + +Git keeps all of its files in the `.git` directory. +To recover from this little mistake, Dracula can just remove the `.git` +folder in the moons subdirectory by running the following command from inside the `planets` directory: + +```bash +$ rm -rf moons/.git +``` + +But be careful! Running this command in the wrong directory will remove +the entire Git history of a project you might want to keep. +Therefore, always check your current directory using the command `pwd`. + + + +::::::::::::::::::::::::: + +:::::::::::::::::::::::::::::::::::::::::::::::::: + +:::::::::::::::::::::::::::::::::::::::: keypoints + +- `git init` initializes a repository. +- Git stores all of its repository data in the `.git` directory. + +:::::::::::::::::::::::::::::::::::::::::::::::::: + + diff --git a/04-changes.md b/04-changes.md new file mode 100644 index 0000000..0bb9dc5 --- /dev/null +++ b/04-changes.md @@ -0,0 +1,801 @@ +--- +title: Tracking Changes +teaching: 25 +exercises: 0 +--- + +::::::::::::::::::::::::::::::::::::::: objectives + +- Go through the modify-add-commit cycle for one or more files. +- Explain where information is stored at each stage of that cycle. +- Distinguish between descriptive and non-descriptive commit messages. + +:::::::::::::::::::::::::::::::::::::::::::::::::: + +:::::::::::::::::::::::::::::::::::::::: questions + +- How do I record changes in Git? +- How do I check the status of my version control repository? +- How do I record notes about what changes I made and why? + +:::::::::::::::::::::::::::::::::::::::::::::::::: + +:::::::::::::::::::::::::::::::::::::::: instructor +We suggest to use slides. From slide 5 onwards: +https://esciencecenter-digital-skills.github.io/digital-skills-slides/modules/git-lesson/git-slides#/5 +Please switch back and forth between command line and slides when necessary. +:::::::::::::::::::::::::::::::::::::::::::::::::: + +First let's make sure we're still in the right directory. +You should be in the `planets` directory. + +```bash +$ cd ~/Desktop/planets +``` + +Let's create a file called `mars.txt` that contains some notes +about the Red Planet's suitability as a base. +We'll use `nano` to edit the file; +you can use whatever editor you like. +In particular, this does not have to be the `core.editor` you set globally earlier. But remember, the bash command to create or edit a new file will depend on the editor you choose (it might not be `nano`). For a refresher on text editors, check out ["Which Editor?"](https://swcarpentry.github.io/shell-novice/03-create.html#which-editor) in [The Unix Shell](https://swcarpentry.github.io/shell-novice/) lesson. + +```bash +$ nano mars.txt +``` + +Type the text below into the `mars.txt` file: + +```output +Cold and dry, but everything is my favorite color +``` + +Let's first verify that the file was properly created by running the list command (`ls`): + +```bash +$ ls +``` + +```output +mars.txt +``` + +`mars.txt` contains a single line, which we can see by running: + +```bash +$ cat mars.txt +``` + +```output +Cold and dry, but everything is my favorite color +``` + +If we check the status of our project again, +Git tells us that it's noticed the new file: + +```bash +$ git status +``` + +```output +On branch main + +No commits yet + +Untracked files: + (use "git add ..." to include in what will be committed) + + mars.txt + +nothing added to commit but untracked files present (use "git add" to track) +``` + +The "untracked files" message means that there's a file in the directory +that Git isn't keeping track of. +We can tell Git to track a file using `git add`: + +```bash +$ git add mars.txt +``` + +and then check that the right thing happened: + +```bash +$ git status +``` + +```output +On branch main + +No commits yet + +Changes to be committed: + (use "git rm --cached ..." to unstage) + + new file: mars.txt + +``` + +Git now knows that it's supposed to keep track of `mars.txt`, +but it hasn't recorded these changes as a commit yet. +To get it to do that, +we need to run one more command: + +```bash +$ git commit -m "Start notes on Mars as a base" +``` + +```output +[main (root-commit) f22b25e] Start notes on Mars as a base + 1 file changed, 1 insertion(+) + create mode 100644 mars.txt +``` + +When we run `git commit`, +Git takes everything we have told it to save by using `git add` +and stores a copy permanently inside the special `.git` directory. +This permanent copy is called a [commit](../learners/reference.md#commit) +(or [revision](../learners/reference.md#revision)) and its short identifier is `f22b25e`. Your commit may have another identifier. + +We use the `-m` flag (for "message") +to record a short, descriptive, and specific comment that will help us remember later on what we did and why. +If we just run `git commit` without the `-m` option, +Git will launch `nano` (or whatever other editor we configured as `core.editor`) +so that we can write a longer message. + +[Good commit messages][commit-messages] start with a brief (\<50 characters) statement about the +changes made in the commit. Generally, the message should complete the sentence "If applied, this commit will" . +If you want to go into more detail, add a blank line between the summary line and your additional notes. Use this additional space to explain why you made changes and/or what their impact will be. + +If we run `git status` now: + +```bash +$ git status +``` + +```output +On branch main +nothing to commit, working tree clean +``` + +it tells us everything is up to date. +If we want to know what we've done recently, +we can ask Git to show us the project's history using `git log`: + +```bash +$ git log +``` + +```output +commit f22b25e3233b4645dabd0d81e651fe074bd8e73b +Author: Vlad Dracula +Date: Thu Aug 22 09:51:46 2013 -0400 + + Start notes on Mars as a base +``` + +`git log` lists all commits made to a repository in reverse chronological order. +The listing for each commit includes +the commit's full identifier +(which starts with the same characters as +the short identifier printed by the `git commit` command earlier), +the commit's author, +when it was created, +and the log message Git was given when the commit was created. + +::::::::::::::::::::::::::::::::::::::::: callout + +## Where Are My Changes? + +If we run `ls` at this point, we will still see just one file called `mars.txt`. +That's because Git saves information about files' history +in the special `.git` directory mentioned earlier +so that our filesystem doesn't become cluttered +(and so that we can't accidentally edit or delete an old version). + + +:::::::::::::::::::::::::::::::::::::::::::::::::: + +Now suppose Dracula adds more information to the file. +(Again, we'll edit with `nano` and then `cat` the file to show its contents; +you may use a different editor, and don't need to `cat`.) + +```bash +$ nano mars.txt +$ cat mars.txt +``` + +```output +Cold and dry, but everything is my favorite color +The two moons may be a problem for Wolfman +``` + +When we run `git status` now, +it tells us that a file it already knows about has been modified: + +```bash +$ git status +``` + +```output +On branch main +Changes not staged for commit: + (use "git add ..." to update what will be committed) + (use "git restore ..." to discard changes in working directory) + + modified: mars.txt + +no changes added to commit (use "git add" and/or "git commit -a") +``` + +The last line is the key phrase: +"no changes added to commit". +We have changed this file, +but we haven't told Git we will want to save those changes +(which we do with `git add`) +nor have we saved them (which we do with `git commit`). +So let's do that now. It is good practice to always review +our changes before saving them. We do this using `git diff`. +This shows us the differences between the current state +of the file and the most recently saved version: + +```bash +$ git diff +``` + +```output +diff --git a/mars.txt b/mars.txt +index df0654a..315bf3a 100644 +--- a/mars.txt ++++ b/mars.txt +@@ -1 +1,2 @@ + Cold and dry, but everything is my favorite color ++The two moons may be a problem for Wolfman +``` + +The output is cryptic because +it is actually a series of commands for tools like editors and `patch` +telling them how to reconstruct one file given the other. +If we break it down into pieces: + +1. The first line tells us that Git is producing output similar to the Unix `diff` command + comparing the old and new versions of the file. +2. The second line tells exactly which versions of the file + Git is comparing; + `df0654a` and `315bf3a` are unique computer-generated labels for those versions. +3. The third and fourth lines once again show the name of the file being changed. +4. The remaining lines are the most interesting, they show us the actual differences + and the lines on which they occur. + In particular, + the `+` marker in the first column shows where we added a line. + +After reviewing our change, it's time to commit it: + +```bash +$ git commit -m "Add concerns about effects of Mars' moons on Wolfman" +``` + +```output +On branch main +Changes not staged for commit: + (use "git add ..." to update what will be committed) + (use "git restore ..." to discard changes in working directory) + + modified: mars.txt + +no changes added to commit (use "git add" and/or "git commit -a") +``` + +Whoops: +Git won't commit because we didn't use `git add` first. +Let's fix that: + +```bash +$ git add mars.txt +$ git commit -m "Add concerns about effects of Mars' moons on Wolfman" +``` + +```output +[main 34961b1] Add concerns about effects of Mars' moons on Wolfman + 1 file changed, 1 insertion(+) +``` + +Git insists that we add files to the set we want to commit +before actually committing anything. This allows us to commit our +changes in stages and capture changes in logical portions rather than +only large batches. +For example, +suppose we're adding a few citations to relevant research to our thesis. +We might want to commit those additions, +and the corresponding bibliography entries, +but *not* commit some of our work drafting the conclusion +(which we haven't finished yet). + +To allow for this, +Git has a special *staging area* +where it keeps track of things that have been added to +the current [changeset](../learners/reference.md#changeset) +but not yet committed. + +::::::::::::::::::::::::::::::::::::::::: callout + +## Staging Area + +If you think of Git as taking snapshots of changes over the life of a project, +`git add` specifies *what* will go in a snapshot +(putting things in the staging area), +and `git commit` then *actually takes* the snapshot, and +makes a permanent record of it (as a commit). +If you don't have anything staged when you type `git commit`, +Git will prompt you to use `git commit -a` or `git commit --all`, +which is kind of like gathering *everyone* to take a group photo! +However, it's almost always better to +explicitly add things to the staging area, because you might +commit changes you forgot you made. (Going back to the group photo simile, +you might get an extra with incomplete makeup walking on +the stage for the picture because you used `-a`!) +Try to stage things manually, +or you might find yourself searching for "git undo commit" more +than you would like! + + +:::::::::::::::::::::::::::::::::::::::::::::::::: + +![](fig/git-staging-area.svg){alt='The Git Staging Area'} + +Let's watch as our changes to a file move from our editor +to the staging area +and into long-term storage. +First, +we'll add another line to the file: + +```bash +$ nano mars.txt +$ cat mars.txt +``` + +```output +Cold and dry, but everything is my favorite color +The two moons may be a problem for Wolfman +But the Mummy will appreciate the lack of humidity +``` + +```bash +$ git diff +``` + +```output +diff --git a/mars.txt b/mars.txt +index 315bf3a..b36abfd 100644 +--- a/mars.txt ++++ b/mars.txt +@@ -1,2 +1,3 @@ + Cold and dry, but everything is my favorite color + The two moons may be a problem for Wolfman ++But the Mummy will appreciate the lack of humidity +``` + +So far, so good: +we've added one line to the end of the file +(shown with a `+` in the first column). +Now let's put that change in the staging area +and see what `git diff` reports: + +```bash +$ git add mars.txt +$ git diff +``` + +There is no output: +as far as Git can tell, +there's no difference between what it's been asked to save permanently +and what's currently in the directory. +However, +if we do this: + +```bash +$ git diff --staged +``` + +```output +diff --git a/mars.txt b/mars.txt +index 315bf3a..b36abfd 100644 +--- a/mars.txt ++++ b/mars.txt +@@ -1,2 +1,3 @@ + Cold and dry, but everything is my favorite color + The two moons may be a problem for Wolfman ++But the Mummy will appreciate the lack of humidity +``` + +it shows us the difference between +the last committed change +and what's in the staging area. +Let's save our changes: + +```bash +$ git commit -m "Discuss concerns about Mars' climate for Mummy" +``` + +```output +[main 005937f] Discuss concerns about Mars' climate for Mummy + 1 file changed, 1 insertion(+) +``` + +check our status: + +```bash +$ git status +``` + +```output +On branch main +nothing to commit, working tree clean +``` + +and look at the history of what we've done so far: + +```bash +$ git log +``` + +```output +commit 005937fbe2a98fb83f0ade869025dc2636b4dad5 (HEAD -> main) +Author: Vlad Dracula +Date: Thu Aug 22 10:14:07 2013 -0400 + + Discuss concerns about Mars' climate for Mummy + +commit 34961b159c27df3b475cfe4415d94a6d1fcd064d +Author: Vlad Dracula +Date: Thu Aug 22 10:07:21 2013 -0400 + + Add concerns about effects of Mars' moons on Wolfman + +commit f22b25e3233b4645dabd0d81e651fe074bd8e73b +Author: Vlad Dracula +Date: Thu Aug 22 09:51:46 2013 -0400 + + Start notes on Mars as a base +``` + +::::::::::::::::::::::::::::::::::::::::: callout + +## Word-based diffing + +Sometimes, e.g. in the case of the text documents a line-wise +diff is too coarse. That is where the `--color-words` option of +`git diff` comes in very useful as it highlights the changed +words using colors. + + +:::::::::::::::::::::::::::::::::::::::::::::::::: + +::::::::::::::::::::::::::::::::::::::::: callout + +## Paging the Log + +When the output of `git log` is too long to fit in your screen, +`git` uses a program to split it into pages of the size of your screen. +When this "pager" is called, you will notice that the last line in your +screen is a `:`, instead of your usual prompt. + +- To get out of the pager, press Q. +- To move to the next page, press Spacebar. +- To search for `some_word` in all pages, + press / + and type `some_word`. + Navigate through matches pressing N. + + +:::::::::::::::::::::::::::::::::::::::::::::::::: + +::::::::::::::::::::::::::::::::::::::::: callout + +## Limit Log Size + +To avoid having `git log` cover your entire terminal screen, you can limit the +number of commits that Git lists by using `-N`, where `N` is the number of +commits that you want to view. For example, if you only want information from +the last commit you can use: + +```bash +$ git log -1 +``` + +```output +commit 005937fbe2a98fb83f0ade869025dc2636b4dad5 (HEAD -> main) +Author: Vlad Dracula +Date: Thu Aug 22 10:14:07 2013 -0400 + + Discuss concerns about Mars' climate for Mummy +``` + +You can also reduce the quantity of information using the +`--oneline` option: + +```bash +$ git log --oneline +``` + +```output +005937f (HEAD -> main) Discuss concerns about Mars' climate for Mummy +34961b1 Add concerns about effects of Mars' moons on Wolfman +f22b25e Start notes on Mars as a base +``` + +You can also combine the `--oneline` option with others. One useful +combination adds `--graph` to display the commit history as a text-based +graph and to indicate which commits are associated with the +current `HEAD`, the current branch `main`, or +[other Git references][git-references]: + +```bash +$ git log --oneline --graph +``` + +```output +* 005937f (HEAD -> main) Discuss concerns about Mars' climate for Mummy +* 34961b1 Add concerns about effects of Mars' moons on Wolfman +* f22b25e Start notes on Mars as a base +``` + +:::::::::::::::::::::::::::::::::::::::::::::::::: + +::::::::::::::::::::::::::::::::::::::::: callout + +## Directories + +Two important facts you should know about directories in Git. + +1. Git does not track directories on their own, only files within them. + Try it for yourself: + + ```bash + $ mkdir spaceships + $ git status + $ git add spaceships + $ git status + ``` + + Note, our newly created empty directory `spaceships` does not appear in + the list of untracked files even if we explicitly add it (*via* `git add`) to our + repository. This is the reason why you will sometimes see `.gitkeep` files + in otherwise empty directories. Unlike `.gitignore`, these files are not special + and their sole purpose is to populate a directory so that Git adds it to + the repository. In fact, you can name such files anything you like. + +2. If you create a directory in your Git repository and populate it with files, + you can add all files in the directory at once by: + + ```bash + git add + ``` + + Try it for yourself: + + ```bash + $ touch spaceships/apollo-11 spaceships/sputnik-1 + $ git status + $ git add spaceships + $ git status + ``` + + Before moving on, we will commit these changes. + + ```bash + $ git commit -m "Add some initial thoughts on spaceships" + ``` + +:::::::::::::::::::::::::::::::::::::::::::::::::: + +To recap, when we want to add changes to our repository, +we first need to add the changed files to the staging area +(`git add`) and then commit the staged changes to the +repository (`git commit`): + +![](fig/git-committing.svg){alt='The Git Commit Workflow'} + +::::::::::::::::::::::::::::::::::::::: challenge + +## Choosing a Commit Message + +Which of the following commit messages would be most appropriate for the +last commit made to `mars.txt`? + +1. "Changes" +2. "Added line 'But the Mummy will appreciate the lack of humidity' to mars.txt" +3. "Discuss effects of Mars' climate on the Mummy" + +::::::::::::::: solution + +## Solution + +Answer 1 is not descriptive enough, and the purpose of the commit is unclear; +and answer 2 is redundant to using "git diff" to see what changed in this commit; +but answer 3 is good: short, descriptive, and imperative. + + + +::::::::::::::::::::::::: + +:::::::::::::::::::::::::::::::::::::::::::::::::: + +::::::::::::::::::::::::::::::::::::::: challenge + +## Committing Changes to Git + +Which command(s) below would save the changes of `myfile.txt` +to my local Git repository? + +1. ```bash + $ git commit -m "my recent changes" + ``` +2. ```bash + $ git init myfile.txt + $ git commit -m "my recent changes" + ``` +3. ```bash + $ git add myfile.txt + $ git commit -m "my recent changes" + ``` +4. ```bash + $ git commit -m myfile.txt "my recent changes" + ``` + +::::::::::::::: solution + +## Solution + +1. Would only create a commit if files have already been staged. +2. Would try to create a new repository. +3. Is correct: first add the file to the staging area, then commit. +4. Would try to commit a file "my recent changes" with the message myfile.txt. + + + +::::::::::::::::::::::::: + +:::::::::::::::::::::::::::::::::::::::::::::::::: + +::::::::::::::::::::::::::::::::::::::: challenge + +## Committing Multiple Files + +The staging area can hold changes from any number of files +that you want to commit as a single snapshot. + +1. Add some text to `mars.txt` noting your decision + to consider Venus as a base +2. Create a new file `venus.txt` with your initial thoughts + about Venus as a base for you and your friends +3. Add changes from both files to the staging area, + and commit those changes. + +::::::::::::::: solution + +## Solution + +The output below from `cat mars.txt` reflects only content added during +this exercise. Your output may vary. + +First we make our changes to the `mars.txt` and `venus.txt` files: + +```bash +$ nano mars.txt +$ cat mars.txt +``` + +```output +Maybe I should start with a base on Venus. +``` + +```bash +$ nano venus.txt +$ cat venus.txt +``` + +```output +Venus is a nice planet and I definitely should consider it as a base. +``` + +Now you can add both files to the staging area. We can do that in one line: + +```bash +$ git add mars.txt venus.txt +``` + +Or with multiple commands: + +```bash +$ git add mars.txt +$ git add venus.txt +``` + +Now the files are ready to commit. You can check that using `git status`. If you are ready to commit use: + +```bash +$ git commit -m "Write plans to start a base on Venus" +``` + +```output +[main cc127c2] + Write plans to start a base on Venus + 2 files changed, 2 insertions(+) + create mode 100644 venus.txt +``` + +::::::::::::::::::::::::: + +:::::::::::::::::::::::::::::::::::::::::::::::::: + +::::::::::::::::::::::::::::::::::::::: challenge + +## `bio` Repository + +- Create a new Git repository on your computer called `bio`. +- Write a three-line biography for yourself in a file called `me.txt`, + commit your changes +- Modify one line, add a fourth line +- Display the differences + between its updated state and its original state. + +::::::::::::::: solution + +## Solution + +If needed, move out of the `planets` folder: + +```bash +$ cd .. +``` + +Create a new folder called `bio` and 'move' into it: + +```bash +$ mkdir bio +$ cd bio +``` + +Initialise git: + +```bash +$ git init +``` + +Create your biography file `me.txt` using `nano` or another text editor. +Once in place, add and commit it to the repository: + +```bash +$ git add me.txt +$ git commit -m "Add biography file" +``` + +Modify the file as described (modify one line, add a fourth line). +To display the differences +between its updated state and its original state, use `git diff`: + +```bash +$ git diff me.txt +``` + +::::::::::::::::::::::::: + +:::::::::::::::::::::::::::::::::::::::::::::::::: + + + +[commit-messages]: https://chris.beams.io/posts/git-commit/ +[git-references]: https://git-scm.com/book/en/v2/Git-Internals-Git-References + + +:::::::::::::::::::::::::::::::::::::::: keypoints + +- `git status` shows the status of a repository. +- Files can be stored in a project's working directory (which users see), the staging area (where the next commit is being built up) and the local repository (where commits are permanently recorded). +- `git add` puts files in the staging area. +- `git commit` saves the staged content as a new commit in the local repository. +- Write a commit message that accurately describes your changes. + +:::::::::::::::::::::::::::::::::::::::::::::::::: + + diff --git a/05-history.md b/05-history.md new file mode 100644 index 0000000..d8ea9e5 --- /dev/null +++ b/05-history.md @@ -0,0 +1,582 @@ +--- +title: Exploring History +teaching: 25 +exercises: 0 +--- + +::::::::::::::::::::::::::::::::::::::: objectives + +- Explain what the HEAD of a repository is and how to use it. +- Identify and use Git commit numbers. +- Compare various versions of tracked files. +- Restore old versions of files. + +:::::::::::::::::::::::::::::::::::::::::::::::::: + +:::::::::::::::::::::::::::::::::::::::: questions + +- How can I identify old versions of files? +- How do I review my changes? +- How can I recover old versions of files? + +:::::::::::::::::::::::::::::::::::::::::::::::::: + +:::::::::::::::::::::::::::::::::::::::: instructor +There are no specific slides for this episode. You could consider keeping the slides open to the episode on the basics of Git, to show the visual representation of the changes in the repository. + +Consider doing this episode as a demo and not going into the details. The aim is to demonstrate to participants the possiblity to go back and forth through the git log, which is enough for an introduction to git. In practice you only use this occasionally. + +Make use of git switch and git restore instead of the confusing git checkout. This is probably much clearer for participants. We haven't tried this yet and it is not in the training material, so you have to do some pioneering. + +:::::::::::::::::::::::::::::::::::::::::::::::::: + +As we saw in the previous episode, we can refer to commits by their +identifiers. You can refer to the *most recent commit* of the working +directory by using the identifier `HEAD`. + +We've been adding one line at a time to `mars.txt`, so it's easy to track our +progress by looking, so let's do that using our `HEAD`s. Before we start, +let's make a change to `mars.txt`, adding yet another line. + +```bash +$ nano mars.txt +$ cat mars.txt +``` + +```output +Cold and dry, but everything is my favorite color +The two moons may be a problem for Wolfman +But the Mummy will appreciate the lack of humidity +An ill-considered change +``` + +Now, let's see what we get. + +```bash +$ git diff HEAD mars.txt +``` + +```output +diff --git a/mars.txt b/mars.txt +index b36abfd..0848c8d 100644 +--- a/mars.txt ++++ b/mars.txt +@@ -1,3 +1,4 @@ + Cold and dry, but everything is my favorite color + The two moons may be a problem for Wolfman + But the Mummy will appreciate the lack of humidity ++An ill-considered change. +``` + +which is the same as what you would get if you leave out `HEAD` (try it). The +real goodness in all this is when you can refer to previous commits. We do +that by adding `~1` +(where "~" is "tilde", pronounced [**til**\-d*uh*]) +to refer to the commit one before `HEAD`. + +```bash +$ git diff HEAD~1 mars.txt +``` + +If we want to see the differences between older commits we can use `git diff` +again, but with the notation `HEAD~1`, `HEAD~2`, and so on, to refer to them: + +```bash +$ git diff HEAD~3 mars.txt +``` + +```output +diff --git a/mars.txt b/mars.txt +index df0654a..b36abfd 100644 +--- a/mars.txt ++++ b/mars.txt +@@ -1 +1,4 @@ + Cold and dry, but everything is my favorite color ++The two moons may be a problem for Wolfman ++But the Mummy will appreciate the lack of humidity ++An ill-considered change +``` + +We could also use `git show` which shows us what changes we made at an older commit as +well as the commit message, rather than the *differences* between a commit and our +working directory that we see by using `git diff`. + +```bash +$ git show HEAD~3 mars.txt +``` + +```output +commit f22b25e3233b4645dabd0d81e651fe074bd8e73b +Author: Vlad Dracula +Date: Thu Aug 22 09:51:46 2013 -0400 + + Start notes on Mars as a base + +diff --git a/mars.txt b/mars.txt +new file mode 100644 +index 0000000..df0654a +--- /dev/null ++++ b/mars.txt +@@ -0,0 +1 @@ ++Cold and dry, but everything is my favorite color +``` + +In this way, +we can build up a chain of commits. +The most recent end of the chain is referred to as `HEAD`; +we can refer to previous commits using the `~` notation, +so `HEAD~1` +means "the previous commit", +while `HEAD~123` goes back 123 commits from where we are now. + +We can also refer to commits using +those long strings of digits and letters +that `git log` displays. +These are unique IDs for the changes, +and "unique" really does mean unique: +every change to any set of files on any computer +has a unique 40-character identifier. +Our first commit was given the ID +`f22b25e3233b4645dabd0d81e651fe074bd8e73b`, +so let's try this: + +```bash +$ git diff f22b25e3233b4645dabd0d81e651fe074bd8e73b mars.txt +``` + +```output +diff --git a/mars.txt b/mars.txt +index df0654a..93a3e13 100644 +--- a/mars.txt ++++ b/mars.txt +@@ -1 +1,4 @@ + Cold and dry, but everything is my favorite color ++The two moons may be a problem for Wolfman ++But the Mummy will appreciate the lack of humidity ++An ill-considered change +``` + +That's the right answer, +but typing out random 40-character strings is annoying, +so Git lets us use just the first few characters (typically seven for normal size projects): + +```bash +$ git diff f22b25e mars.txt +``` + +```output +diff --git a/mars.txt b/mars.txt +index df0654a..93a3e13 100644 +--- a/mars.txt ++++ b/mars.txt +@@ -1 +1,4 @@ + Cold and dry, but everything is my favorite color ++The two moons may be a problem for Wolfman ++But the Mummy will appreciate the lack of humidity ++An ill-considered change +``` + +All right! So +we can save changes to files and see what we've changed. Now, how +can we restore older versions of things? +Let's suppose we change our mind about the last update to +`mars.txt` (the "ill-considered change"). + +`git status` now tells us that the file has been changed, +but those changes haven't been staged: + +```bash +$ git status +``` + +```output +On branch main +Changes not staged for commit: + (use "git add ..." to update what will be committed) + (use "git restore ..." to discard changes in working directory) + + modified: mars.txt + +no changes added to commit (use "git add" and/or "git commit -a") +``` + +We can put things back the way they were +by using `git restore`: + +```bash +$ git restore mars.txt +$ cat mars.txt +``` + +```output +Cold and dry, but everything is my favorite color +The two moons may be a problem for Wolfman +But the Mummy will appreciate the lack of humidity +``` + +As you might guess from its name, +`git restore` restores an old version of a file. +In this case, +we're telling Git that we want to recover the version of the file recorded in `HEAD`, +which is the last saved commit. +If we want to go back even further, +we can use the 'source' flag `-s` to specify a commit identifier instead: + +```bash +$ git restore -s f22b25e mars.txt +``` + +```bash +$ cat mars.txt +``` + +```output +Cold and dry, but everything is my favorite color +``` + +```bash +$ git status +``` + +```output +On branch main +Changes not staged for commit: + (use "git add ..." to update what will be committed) + (use "git restore ..." to discard changes in working directory) + + modified: mars.txt + +``` + +Again, we can put things back the way they were +by using `git restore`: + +```bash +$ git restore mars.txt +``` + +It's important to remember that +we must use the commit number that identifies the state of the repository +*before* the change we're trying to undo. +A common mistake is to use the number of +the commit in which we made the change we're trying to discard. +In the example below, we want to retrieve the state from before the most +recent commit (`HEAD~1`), which is commit `f22b25e`: + +![](fig/git-restore.svg){alt='Git Restore'} + +So, to put it all together, +here's how Git works in cartoon form: + +![https://figshare.com/articles/How_Git_works_a_cartoon/1328266](fig/git_staging.svg){alt='Git Staging'} + +::::::::::::::::::::::::::::::::::::::::: callout + +## Simplifying the Common Case + +If you read the output of `git status` carefully, +you'll see that it includes this hint: + +```output +(use "git restore ..." to discard changes in working directory) +``` + +As it says, +`git restore` without a version identifier restores files to the state saved in `HEAD`. + +:::::::::::::::::::::::::::::::::::::::::::::::::: + +The fact that files can be reverted one by one +tends to change the way people organize their work. +If everything is in one large document, +it's hard (but not impossible) to undo changes to the introduction +without also undoing changes made later to the conclusion. +If the introduction and conclusion are stored in separate files, +on the other hand, +moving backward and forward in time becomes much easier. + +::::::::::::::::::::::::::::::::::::::: challenge + +## Recovering Older Versions of a File + +Jennifer has made changes to the Python script that she has been working on for weeks, and the +modifications she made this morning "broke" the script and it no longer runs. She has spent +\~ 1hr trying to fix it, with no luck... + +Luckily, she has been keeping track of her project's versions using Git! Which commands below will +let her recover the last committed version of her Python script called +`data_cruncher.py`? + +1. `$ git restore` + +2. `$ git restore data_cruncher.py` + +3. `$ git restore -s HEAD~1 data_cruncher.py` + +4. `$ git restore -s data_cruncher.py` + +5. Both 2 and 4 + +::::::::::::::: solution + +## Solution + +The answer is (5)-Both 2 and 4. + +The `restore` command restores files from the repository, overwriting the files in your working +directory. Answers 2 and 4 both restore the *latest* version *in the repository* of the file +`data_cruncher.py`. Answer 2 doesn't specify a commit, which means it automatically refers to the +*latest*, whereas answer 4 uses the unique ID of the last commit, which would be the same as +using `HEAD` instead. + +Answer 3 gets the version of `data_cruncher.py` from the commit *before* `HEAD`, which is NOT +what we wanted. + +Answer 1 reports an error `fatal: you must specify path(s) to restore`: you haven't specified +which file(s) to restore. It's a good idea to be specific about which files you mean,so you +don't accidentally restore more files than you need. If you do want to restore all previously +committed files in your repository, you can use `.` to specify the current folder (and all +subfolders), i.e., `git restore .`. + + +::::::::::::::::::::::::: + +:::::::::::::::::::::::::::::::::::::::::::::::::: + +::::::::::::::::::::::::::::::::::::::: challenge + +## Reverting a Commit + +Jennifer is collaborating with colleagues on her Python script. She +realizes her last commit to the project's repository contained an error, and +wants to undo it. Jennifer wants to undo correctly so everyone in the project's +repository gets the correct change. The command `git revert [erroneous commit ID]` will create a +new commit that reverses the erroneous commit. + +The command `git revert` is +different from `git restore -s [commit ID]` because `git restore` returns the +files not yet committed within the local repository to a previous state, whereas `git revert` +reverses changes committed to the local and project repositories. + +Below are the right steps and explanations for Jennifer to use `git revert`, +what is the missing command? + +1. `________ # Look at the git history of the project to find the commit ID` + +2. Copy the ID (the first few characters of the ID, e.g. 0b1d055). + +3. `git revert [commit ID]` + +4. Type in the new commit message. + +5. Save and close + +::::::::::::::: solution + +## Solution + +The command `git log` lists project history with commit IDs. + +The command `git show HEAD` shows changes made at the latest commit, and lists +the commit ID; however, Jennifer should double-check it is the correct commit, and no one +else has committed changes to the repository. + + + +::::::::::::::::::::::::: + +:::::::::::::::::::::::::::::::::::::::::::::::::: + +::::::::::::::::::::::::::::::::::::::: challenge + +## Understanding Workflow and History + +What is the output of the last command in + +```bash +$ cd planets +$ echo "Venus is beautiful and full of love" > venus.txt +$ git add venus.txt +$ echo "Venus is too hot to be suitable as a base" >> venus.txt +$ git commit -m "Comment on Venus as an unsuitable base" +$ git restore venus.txt +$ cat venus.txt #this will print the contents of venus.txt to the screen +``` + +1. ```output + Venus is too hot to be suitable as a base + ``` +2. ```output + Venus is beautiful and full of love + ``` +3. ```output + Venus is beautiful and full of love + Venus is too hot to be suitable as a base + ``` +4. ```output + Error because you have changed venus.txt without committing the changes + ``` + +::::::::::::::: solution + +## Solution + +The answer is 2. + +The command `git add venus.txt` places the current version of `venus.txt` into the staging area. +The changes to the file from the second `echo` command are only applied to the working copy, +not the version in the staging area. + +So, when `git commit -m "Comment on Venus as an unsuitable base"` is executed, +the version of `venus.txt` committed to the repository is the one from the staging area and +has only one line. + +At this time, the working copy still has the second line (and +`git status` will show that the file is modified). However, `git restore venus.txt` +replaces the working copy with the most recently committed version of `venus.txt`. + +So, `cat venus.txt` will output + +```output +Venus is beautiful and full of love. +``` + +::::::::::::::::::::::::: + +:::::::::::::::::::::::::::::::::::::::::::::::::: + +::::::::::::::::::::::::::::::::::::::: challenge + +## Checking Understanding of `git diff` + +Consider this command: `git diff HEAD~9 mars.txt`. What do you predict this command +will do if you execute it? What happens when you do execute it? Why? + +Try another command, `git diff [ID] mars.txt`, where [ID] is replaced with +the unique identifier for your most recent commit. What do you think will happen, +and what does happen? + + +:::::::::::::::::::::::::::::::::::::::::::::::::: + +::::::::::::::::::::::::::::::::::::::: challenge + +## Getting Rid of Staged Changes + +`git restore` can be used to restore a previous commit when unstaged changes have +been made, but will it also work for changes that have been staged but not committed? +Make a change to `mars.txt`, add that change using `git add`, +then use `git restore` to see if you can remove your change. + +::::::::::::::: solution + +## Solution + +After adding a change, `git restore` can not be used directly. +Let's look at the output of `git status`: + +```output +On branch main +Changes to be committed: + (use "git restore --staged ..." to unstage) + + modified: mars.txt + +``` + +Note that if you don't have the same output +you may either have forgotten to change the file, +or you have added it *and* committed it. + +Using the command `git restore mars.txt` now does not give an error, +but it does not restore the file either. +Git helpfully tells us that we need to use `git restore --staged` instead +to unstage the file: + +```bash +$ git restore --staged mars.txt +``` + +Now, `git status` gives us: + +```bash +$ git status +``` + +```output +On branch main +Changes not staged for commit: + (use "git add ..." to update what will be committed) + (use "git restore ..." to discard changes in working directory) + + modified: mars.txt + +no changes added to commit (use "git add" and/or "git commit -a") +``` + +This means we can now use `git restore` to restore the file +to the previous commit: + +```bash +$ git restore mars.txt +$ git status +``` + +```output +On branch main +nothing to commit, working tree clean +``` + +::::::::::::::::::::::::: + +:::::::::::::::::::::::::::::::::::::::::::::::::: + +::::::::::::::::::::::::::::::::::::::: challenge + +## Explore and Summarize Histories + +Exploring history is an important part of Git, and often it is a challenge to find +the right commit ID, especially if the commit is from several months ago. + +Imagine the `planets` project has more than 50 files. +You would like to find a commit that modifies some specific text in `mars.txt`. +When you type `git log`, a very long list appeared. +How can you narrow down the search? + +Recall that the `git diff` command allows us to explore one specific file, +e.g., `git diff mars.txt`. We can apply a similar idea here. + +```bash +$ git log mars.txt +``` + +Unfortunately some of these commit messages are very ambiguous, e.g., `update files`. +How can you search through these files? + +Both `git diff` and `git log` are very useful and they summarize a different part of the history +for you. +Is it possible to combine both? Let's try the following: + +```bash +$ git log --patch mars.txt +``` + +You should get a long list of output, and you should be able to see both commit messages and +the difference between each commit. + +Question: What does the following command do? + +```bash +$ git log --patch HEAD~9 *.txt +``` + +:::::::::::::::::::::::::::::::::::::::::::::::::: + +:::::::::::::::::::::::::::::::::::::::: keypoints + +- `git diff` displays differences between commits. +- `git restore` recovers old versions of files. + +:::::::::::::::::::::::::::::::::::::::::::::::::: + + diff --git a/06-ignore.md b/06-ignore.md new file mode 100644 index 0000000..763d735 --- /dev/null +++ b/06-ignore.md @@ -0,0 +1,379 @@ +--- +title: Ignoring Things +teaching: 10 +exercises: 0 +--- + +::::::::::::::::::::::::::::::::::::::: objectives + +- Configure Git to ignore specific files. +- Explain why ignoring files can be useful. + +:::::::::::::::::::::::::::::::::::::::::::::::::: + +:::::::::::::::::::::::::::::::::::::::: questions + +- How can I tell Git to ignore files I don't want to track? + +:::::::::::::::::::::::::::::::::::::::::::::::::: + +:::::::::::::::::::::::::::::::::::::::: instructor +There are no slides associated with this episode. Focus on the main concept of ignoring files with a .gitignore file, instead of fully learning the syntax. + +:::::::::::::::::::::::::::::::::::::::::::::::::: + +What if we have files that we do not want Git to track for us, +like backup files created by our editor +or intermediate files created during data analysis? +Let's create a few dummy files: + +```bash +$ mkdir results +$ touch a.csv b.csv c.csv results/a.out results/b.out +``` + +and see what Git says: + +```bash +$ git status +``` + +```output +On branch main +Untracked files: + (use "git add ..." to include in what will be committed) + + a.csv + b.csv + c.csv + results/ + +nothing added to commit but untracked files present (use "git add" to track) +``` + +Putting these files under version control would be a waste of disk space. +What's worse, +having them all listed could distract us from changes that actually matter, +so let's tell Git to ignore them. + +We do this by creating a file in the root directory of our project called `.gitignore`: + +```bash +$ nano .gitignore +$ cat .gitignore +``` + +```output +*.csv +results/ +``` + +These patterns tell Git to ignore any file whose name ends in `.csv` +and everything in the `results` directory. +(If any of these files were already being tracked, +Git would continue to track them.) + +Once we have created this file, +the output of `git status` is much cleaner: + +```bash +$ git status +``` + +```output +On branch main +Untracked files: + (use "git add ..." to include in what will be committed) + + .gitignore + +nothing added to commit but untracked files present (use "git add" to track) +``` + +The only thing Git notices now is the newly-created `.gitignore` file. +You might think we wouldn't want to track it, +but everyone we're sharing our repository with will probably want to ignore +the same things that we're ignoring. +Let's add and commit `.gitignore`: + +```bash +$ git add .gitignore +$ git commit -m "Ignore data files and the results folder" +$ git status +``` + +```output +On branch main +nothing to commit, working tree clean +``` + +As a bonus, using `.gitignore` helps us avoid accidentally adding files to the repository that we don't want to track: + +```bash +$ git add a.csv +``` + +```output +The following paths are ignored by one of your .gitignore files: +a.csv +Use -f if you really want to add them. +``` + +If we really want to override our ignore settings, +we can use `git add -f` to force Git to add something. For example, +`git add -f a.csv`. +We can also always see the status of ignored files if we want: + +```bash +$ git status --ignored +``` + +```output +On branch main +Ignored files: + (use "git add -f ..." to include in what will be committed) + + a.csv + b.csv + c.csv + results/ + +nothing to commit, working tree clean +``` + +::::::::::::::::::::::::::::::::::::::: challenge + +## Ignoring Nested Files + +Given a directory structure that looks like: + +```bash +results/data +results/plots +``` + +How would you ignore only `results/plots` and not `results/data`? + +::::::::::::::: solution + +## Solution + +If you only want to ignore the contents of +`results/plots`, you can change your `.gitignore` to ignore +only the `/plots/` subfolder by adding the following line to +your .gitignore: + +```output +results/plots/ +``` + +This line will ensure only the contents of `results/plots` is ignored, and +not the contents of `results/data`. + +As with most programming issues, there +are a few alternative ways that one may ensure this ignore rule is followed. +The "Ignoring Nested Files: Variation" exercise has a slightly +different directory structure +that presents an alternative solution. +Further, the discussion page has more detail on ignore rules. + + + +::::::::::::::::::::::::: + +:::::::::::::::::::::::::::::::::::::::::::::::::: + +::::::::::::::::::::::::::::::::::::::: challenge + +## Including Specific Files + +How would you ignore all `.csv` files in your root directory except for +`final.csv`? +Hint: Find out what `!` (the exclamation point operator) does + +::::::::::::::: solution + +## Solution + +You would add the following two lines to your .gitignore: + +```output +*.csv # ignore all data files +!final.csv # except final.csv +``` + +The exclamation point operator will include a previously excluded entry. + +Note also that because you've previously committed `.csv` files in this +lesson they will not be ignored with this new rule. Only future additions +of `.csv` files added to the root directory will be ignored. + + + +::::::::::::::::::::::::: + +:::::::::::::::::::::::::::::::::::::::::::::::::: + +::::::::::::::::::::::::::::::::::::::: challenge + +## Ignoring Nested Files: Variation + +Given a directory structure that looks similar to the earlier Nested Files +exercise, but with a slightly different directory structure: + +```bash +results/data +results/images +results/plots +results/analysis +``` + +How would you ignore all of the contents in the results folder, but not `results/data`? + +Hint: think a bit about how you created an exception with the `!` operator +before. + +::::::::::::::: solution + +## Solution + +If you want to ignore the contents of +`results/` but not those of `results/data/`, you can change your `.gitignore` to ignore +the contents of results folder, but create an exception for the contents of the +`results/data` subfolder. Your .gitignore would look like this: + +```output +results/* # ignore everything in results folder +!results/data/ # do not ignore results/data/ contents +``` + +::::::::::::::::::::::::: + +:::::::::::::::::::::::::::::::::::::::::::::::::: + +::::::::::::::::::::::::::::::::::::::: challenge + +## Ignoring all data Files in a Directory + +Assuming you have an empty .gitignore file, and given a directory structure that looks like: + +```bash +results/data/position/gps/a.csv +results/data/position/gps/b.csv +results/data/position/gps/c.csv +results/data/position/gps/info.txt +results/plots +``` + +What's the shortest `.gitignore` rule you could write to ignore all `.csv` +files in `result/data/position/gps`? Do not ignore the `info.txt`. + +::::::::::::::: solution + +## Solution + +Appending `results/data/position/gps/*.csv` will match every file in `results/data/position/gps` +that ends with `.csv`. +The file `results/data/position/gps/info.txt` will not be ignored. + + + +::::::::::::::::::::::::: + +:::::::::::::::::::::::::::::::::::::::::::::::::: + +::::::::::::::::::::::::::::::::::::::: challenge + +## Ignoring all data Files in the repository + +Let us assume you have many `.csv` files in different subdirectories of your repository. +For example, you might have: + +```bash +results/a.csv +data/experiment_1/b.csv +data/experiment_2/c.csv +data/experiment_2/variation_1/d.csv +``` + +How do you ignore all the `.csv` files, without explicitly listing the names of the corresponding folders? + +::::::::::::::: solution + +## Solution + +In the `.gitignore` file, write: + +```output +**/*.csv +``` + +This will ignore all the `.csv` files, regardless of their position in the directory tree. +You can still include some specific exception with the exclamation point operator. + + + +::::::::::::::::::::::::: + +:::::::::::::::::::::::::::::::::::::::::::::::::: + +::::::::::::::::::::::::::::::::::::::: challenge + +## The Order of Rules + +Given a `.gitignore` file with the following contents: + +```bash +*.csv +!*.csv +``` + +What will be the result? + +::::::::::::::: solution + +## Solution + +The `!` modifier will negate an entry from a previously defined ignore pattern. +Because the `!*.csv` entry negates all of the previous `.csv` files in the `.gitignore`, +none of them will be ignored, and all `.csv` files will be tracked. + +::::::::::::::::::::::::: + +:::::::::::::::::::::::::::::::::::::::::::::::::: + +::::::::::::::::::::::::::::::::::::::: challenge + +## Log Files + +You wrote a script that creates many intermediate log-files of the form `log_01`, `log_02`, `log_03`, etc. +You want to keep them but you do not want to track them through `git`. + +1. Write **one** `.gitignore` entry that excludes files of the form `log_01`, `log_02`, etc. + +2. Test your "ignore pattern" by creating some dummy files of the form `log_01`, etc. + +3. You find that the file `log_01` is very important after all, add it to the tracked files without changing the `.gitignore` again. + +4. Discuss with your neighbor what other types of files could reside in your directory that you do not want to track and thus would exclude via `.gitignore`. + +::::::::::::::: solution + +## Solution + +1. append either `log_*` or `log*` as a new entry in your .gitignore +2. track `log_01` using `git add -f log_01` + + + +::::::::::::::::::::::::: + +:::::::::::::::::::::::::::::::::::::::::::::::::: + +:::::::::::::::::::::::::::::::::::::::: keypoints + +- The `.gitignore` file tells Git what files to ignore. + +:::::::::::::::::::::::::::::::::::::::::::::::::: + + diff --git a/07-github.md b/07-github.md new file mode 100644 index 0000000..b79bd6b --- /dev/null +++ b/07-github.md @@ -0,0 +1,561 @@ +--- +title: Remotes in GitHub +teaching: 45 +exercises: 0 +--- + +::::::::::::::::::::::::::::::::::::::: objectives + +- Explain what remote repositories are and why they are useful. +- Push to or pull from a remote repository. + +:::::::::::::::::::::::::::::::::::::::::::::::::: + + +:::::::::::::::::::::::::::::::::::::::: questions + +- How do I share my changes with others on the web? + +:::::::::::::::::::::::::::::::::::::::::::::::::: + +:::::::::::::::::::::::::::::::::::::::: instructor +There are no slides associated with this episode. Take a dedicated moment right before this episode to check succesful completion of particpants' SSH setup and help out people who did not succeed yet. You will need 15-30 minutes for this. + +:::::::::::::::::::::::::::::::::::::::::::::::::: + +Version control really comes into its own when we begin to collaborate with +other people. We already have most of the machinery we need to do this; the +only thing missing is to copy changes from one repository to another. + +Systems like Git allow us to move work between any two repositories. In +practice, though, it's easiest to use one copy as a central hub, and to keep it +on the web rather than on someone's laptop. Most programmers use hosting +services like [GitHub](https://github.com), [Bitbucket](https://bitbucket.org) or +[GitLab](https://gitlab.com/) to hold those main copies. + +Let's start by sharing the changes we've made to our current project with the +world. To this end we are going to create a *remote* repository that will be linked to our *local* repository. + +## 1\. Create a remote repository + +Log in to [GitHub](https://github.com), then click on the icon in the top right corner to +create a new repository called `planets`: + +![](fig/github-create-repo-01.png){alt='Creating a Repository on GitHub (Step 1)'} + +Name your repository "planets" and then click "Create Repository". + +Note: Since this repository will be connected to a local repository, it needs to be empty. Leave +"Initialize this repository with a README" unchecked, and keep "None" as options for both "Add +.gitignore" and "Add a license." See the "GitHub License and README files" exercise below for a full +explanation of why the repository needs to be empty. + +![](fig/github-create-repo-02.png){alt='Creating a Repository on GitHub (Step 2)'} + +As soon as the repository is created, GitHub displays a page with a URL and some +information on how to configure your local repository: + +![](fig/github-create-repo-03.png){alt='Creating a Repository on GitHub (Step 3)'} + +This effectively does the following on GitHub's servers: + +```bash +$ mkdir planets +$ cd planets +$ git init +``` + +If you remember back to the earlier [episode](04-changes.md) where we added and +committed our earlier work on `mars.txt`, we had a diagram of the local repository +which looked like this: + +![](fig/git-staging-area.svg){alt='The Local Repository with Git Staging Area'} + +Now that we have two repositories, we need a diagram like this: + +![](fig/git-freshly-made-github-repo.svg){alt='Freshly-Made GitHub Repository'} + +Note that our local repository still contains our earlier work on `mars.txt`, but the +remote repository on GitHub appears empty as it doesn't contain any files yet. + +## 2\. Connect local to remote repository + +Now we connect the two repositories. We do this by making the +GitHub repository a [remote](../learners/reference.md#remote) for the local repository. +The home page of the repository on GitHub includes the URL string we need to +identify it: + +![](fig/github-find-repo-string.png){alt='Where to Find Repository URL on GitHub'} + +Click on the 'SSH' link to change the [protocol](../learners/reference.md#protocol) from HTTPS to SSH. + +::::::::::::::::::::::::::::::::::::::::: callout + +## HTTPS vs. SSH + +We use SSH here because, while it requires some additional configuration, it is a +security protocol widely used by many applications. The steps below describe SSH at a +minimum level for GitHub. + + +:::::::::::::::::::::::::::::::::::::::::::::::::: + +![](fig/github-change-repo-string.png){alt='Changing the Repository URL on GitHub'} + +Copy that URL from the browser, go into the local `planets` repository, and run +this command: + +```bash +$ git remote add origin git@github.com:vlad/planets.git +``` + +Make sure to use the URL for your repository rather than Vlad's: the only +difference should be your username instead of `vlad`. + +`origin` is a local name used to refer to the remote repository. It could be called +anything, but `origin` is a convention that is often used by default in git +and GitHub, so it's helpful to stick with this unless there's a reason not to. + +We can check that the command has worked by running `git remote -v`: + +```bash +$ git remote -v +``` + +```output +origin git@github.com:vlad/planets.git (fetch) +origin git@github.com:vlad/planets.git (push) +``` + +We'll discuss remotes in more detail in the next episode, while +talking about how they might be used for collaboration. + +## 3\. SSH Background and Setup + +Before Dracula can connect to a remote repository, he needs to set up a way for his computer to authenticate with GitHub so it knows it's him trying to connect to his remote repository. + +We are going to set up the method that is commonly used by many different services to authenticate access on the command line. This method is called Secure Shell Protocol (SSH). SSH is a cryptographic network protocol that allows secure communication between computers using an otherwise insecure network. + +SSH uses what is called a key pair. This is two keys that work together to validate access. One key is publicly known and called the public key, and the other key called the private key is kept private. Very descriptive names. + +You can think of the public key as a padlock, and only you have the key (the private key) to open it. You use the public key where you want a secure method of communication, such as your GitHub account. You give this padlock, or public key, to GitHub and say "lock the communications to my account with this so that only computers that have my private key can unlock communications and send git commands as my GitHub account." + +What we will do now is the minimum required to set up the SSH keys and add the public key to a GitHub account. + +::::::::::::::::::::::::::::::::::::::::: callout + +## Advanced SSH + +A supplemental episode in this lesson discusses SSH and key pairs in more depth and detail. + + +:::::::::::::::::::::::::::::::::::::::::::::::::: + +The first thing we are going to do is check if this has already been done on the computer you're on. Because generally speaking, this setup only needs to happen once and then you can forget about it. + +::::::::::::::::::::::::::::::::::::::::: callout + +## Keeping your keys secure + +You shouldn't really forget about your SSH keys, since they keep your account secure. It's good +practice to audit your secure shell keys every so often. Especially if you are using multiple +computers to access your account. + + +:::::::::::::::::::::::::::::::::::::::::::::::::: + +We will run the list command to check what key pairs already exist on your computer. + +```bash +ls -al ~/.ssh +``` + +Your output is going to look a little different depending on whether or not SSH has ever been set up on the computer you are using. + +Dracula has not set up SSH on his computer, so his output is + +```output +ls: cannot access '/c/Users/Vlad Dracula/.ssh': No such file or directory +``` + +If SSH has been set up on the computer you're using, the public and private key pairs will be listed. The file names are either `id_ed25519`/`id_ed25519.pub` or `id_rsa`/`id_rsa.pub` depending on how the key pairs were set up. +Since they don't exist on Dracula's computer, he uses this command to create them. + +### 3\.1 Create an SSH key pair + +To create an SSH key pair Vlad uses this command, where the `-t` option specifies which type of algorithm to use and `-C` attaches a comment to the key (here, Vlad's email): + +```bash +$ ssh-keygen -t ed25519 -C "vlad@tran.sylvan.ia" +``` + +If you are using a legacy system that doesn't support the Ed25519 algorithm, use: +`$ ssh-keygen -t rsa -b 4096 -C "your_email@example.com"` + +```output +Generating public/private ed25519 key pair. +Enter file in which to save the key (/c/Users/Vlad Dracula/.ssh/id_ed25519): +``` + +We want to use the default file, so just press Enter. + +```output +Created directory '/c/Users/Vlad Dracula/.ssh'. +Enter passphrase (empty for no passphrase): +``` + +Now, it is prompting Dracula for a passphrase. Since he is using his lab's laptop that other people sometimes have access to, he wants to create a passphrase. Be sure to use something memorable or save your passphrase somewhere, as there is no "reset my password" option. + +```output +Enter same passphrase again: +``` + +After entering the same passphrase a second time, we receive the confirmation + +```output +Your identification has been saved in /c/Users/Vlad Dracula/.ssh/id_ed25519 +Your public key has been saved in /c/Users/Vlad Dracula/.ssh/id_ed25519.pub +The key fingerprint is: +SHA256:SMSPIStNyA00KPxuYu94KpZgRAYjgt9g4BA4kFy3g1o vlad@tran.sylvan.ia +The key's randomart image is: ++--[ED25519 256]--+ +|^B== o. | +|%*=.*.+ | +|+=.E =.+ | +| .=.+.o.. | +|.... . S | +|.+ o | +|+ = | +|.o.o | +|oo+. | ++----[SHA256]-----+ +``` + +The "identification" is actually the private key. You should never share it. The public key is appropriately named. The "key fingerprint" +is a shorter version of a public key. + +Now that we have generated the SSH keys, we will find the SSH files when we check. + +```bash +ls -al ~/.ssh +``` + +```output +drwxr-xr-x 1 Vlad Dracula 197121 0 Jul 16 14:48 ./ +drwxr-xr-x 1 Vlad Dracula 197121 0 Jul 16 14:48 ../ +-rw-r--r-- 1 Vlad Dracula 197121 419 Jul 16 14:48 id_ed25519 +-rw-r--r-- 1 Vlad Dracula 197121 106 Jul 16 14:48 id_ed25519.pub +``` + +### 3\.2 Copy the public key to GitHub + +Now we have a SSH key pair and we can run this command to check if GitHub can read our authentication. + +```bash +ssh -T git@github.com +``` + +```output +The authenticity of host 'github.com (192.30.255.112)' can't be established. +RSA key fingerprint is SHA256:nThbg6kXUpJWGl7E1IGOCspRomTxdCARLviKw6E5SY8. +This key is not known by any other names +Are you sure you want to continue connecting (yes/no/[fingerprint])? y +Please type 'yes', 'no' or the fingerprint: yes +Warning: Permanently added 'github.com' (RSA) to the list of known hosts. +git@github.com: Permission denied (publickey). +``` + +Right, we forgot that we need to give GitHub our public key! + +First, we need to copy the public key. Be sure to include the `.pub` at the end, otherwise you're looking at the private key. + +```bash +cat ~/.ssh/id_ed25519.pub +``` + +```output +ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIDmRA3d51X0uu9wXek559gfn6UFNF69yZjChyBIU2qKI vlad@tran.sylvan.ia +``` + +Now, going to GitHub.com, click on your profile icon in the top right corner to get the drop-down menu. Click "Settings," then on the +settings page, click "SSH and GPG keys," on the left side "Account settings" menu. Click the "New SSH key" button on the right side. Now, +you can add the title (Dracula uses the title "Vlad's Lab Laptop" so he can remember where the original key pair +files are located), paste your SSH key into the field, and click the "Add SSH key" to complete the setup. + +Now that we've set that up, let's check our authentication again from the command line. + +```bash +$ ssh -T git@github.com +``` + +```output +Hi Vlad! You've successfully authenticated, but GitHub does not provide shell access. +``` + +Good! This output confirms that the SSH key works as intended. We are now ready to push our work to the remote repository. + +## 4\. Push local changes to a remote + +Now that authentication is setup, we can return to the remote. This command will push the changes from +our local repository to the repository on GitHub: + +```bash +$ git push origin main +``` + +Since Dracula set up a passphrase, it will prompt him for it. If you completed advanced settings for your authentication, it +will not prompt for a passphrase. + +```output +Enumerating objects: 16, done. +Counting objects: 100% (16/16), done. +Delta compression using up to 8 threads. +Compressing objects: 100% (11/11), done. +Writing objects: 100% (16/16), 1.45 KiB | 372.00 KiB/s, done. +Total 16 (delta 2), reused 0 (delta 0) +remote: Resolving deltas: 100% (2/2), done. +To https://github.com/vlad/planets.git + * [new branch] main -> main +``` + +::::::::::::::::::::::::::::::::::::::::: callout + +## Proxy + +If the network you are connected to uses a proxy, there is a chance that your +last command failed with "Could not resolve hostname" as the error message. To +solve this issue, you need to tell Git about the proxy: + +```bash +$ git config --global http.proxy http://user:password@proxy.url +$ git config --global https.proxy https://user:password@proxy.url +``` + +When you connect to another network that doesn't use a proxy, you will need to +tell Git to disable the proxy using: + +```bash +$ git config --global --unset http.proxy +$ git config --global --unset https.proxy +``` + +:::::::::::::::::::::::::::::::::::::::::::::::::: + +::::::::::::::::::::::::::::::::::::::::: callout + +## Password Managers + +If your operating system has a password manager configured, `git push` will +try to use it when it needs your username and password. For example, this +is the default behavior for Git Bash on Windows. If you want to type your +username and password at the terminal instead of using a password manager, +type: + +```bash +$ unset SSH_ASKPASS +``` + +in the terminal, before you run `git push`. Despite the name, [Git uses +`SSH_ASKPASS` for all credential +entry](https://git-scm.com/docs/gitcredentials#_requesting_credentials), so +you may want to unset `SSH_ASKPASS` whether you are using Git via SSH or +https. + +You may also want to add `unset SSH_ASKPASS` at the end of your `~/.bashrc` +to make Git default to using the terminal for usernames and passwords. + + +:::::::::::::::::::::::::::::::::::::::::::::::::: + +Our local and remote repositories are now in this state: + +![](fig/github-repo-after-first-push.svg){alt='GitHub Repository After First Push'} + +::::::::::::::::::::::::::::::::::::::::: callout + +## The '-u' Flag + +You may see a `-u` option used with `git push` in some documentation. This +option is synonymous with the `--set-upstream-to` option for the `git branch` +command, and is used to associate the current branch with a remote branch so +that the `git pull` command can be used without any arguments. To do this, +simply use `git push -u origin main` once the remote has been set up. + + +:::::::::::::::::::::::::::::::::::::::::::::::::: + +We can pull changes from the remote repository to the local one as well: + +```bash +$ git pull origin main +``` + +```output +From https://github.com/vlad/planets + * branch main -> FETCH_HEAD +Already up-to-date. +``` + +Pulling has no effect in this case because the two repositories are already +synchronized. If someone else had pushed some changes to the repository on +GitHub, though, this command would download them to our local repository. + +::::::::::::::::::::::::::::::::::::::: challenge + +## GitHub GUI + +Browse to your `planets` repository on GitHub. +Underneath the Code button, find and click on the text that says "XX commits" (where "XX" is some number). +Hover over, and click on, the three buttons to the right of each commit. +What information can you gather/explore from these buttons? +How would you get that same information in the shell? + +::::::::::::::: solution + +## Solution + +The left-most button (with the picture of a clipboard) copies the full identifier of the commit +to the clipboard. In the shell, `git log` will show you the full commit identifier for each +commit. + +When you click on the middle button, you'll see all of the changes that were made in that +particular commit. Green shaded lines indicate additions and red ones removals. In the shell we +can do the same thing with `git diff`. In particular, `git diff ID1..ID2` where ID1 and +ID2 are commit identifiers (e.g. `git diff a3bf1e5..041e637`) will show the differences +between those two commits. + +The right-most button lets you view all of the files in the repository at the time of that +commit. To do this in the shell, we'd need to restore the files in the repository to that particular +time. We can do this with `git restore -s ID ` where ID is the identifier of the commit +we want to look at, and `` is the list of files we want to view. To view all files at +at the time of that commit, you can use `git restore -s ID .`. If we do this, we need to +remember to put the repository back to the right state afterwards! + + + +::::::::::::::::::::::::: + +:::::::::::::::::::::::::::::::::::::::::::::::::: + +::::::::::::::::::::::::::::::::::::::::: callout + +## Uploading files directly in GitHub browser + +Github also allows you to skip the command line and upload files directly to +your repository without having to leave the browser. There are two options. +First you can click the "Upload files" button in the toolbar at the top of the +file tree. Or, you can drag and drop files from your desktop onto the file +tree. You can read more about this [on this GitHub page](https://help.github.com/articles/adding-a-file-to-a-repository/). + + +:::::::::::::::::::::::::::::::::::::::::::::::::: + +::::::::::::::::::::::::::::::::::::::: challenge + +## GitHub Timestamp + +Create a remote repository on GitHub. Push the contents of your local +repository to the remote. Make changes to your local repository and push these +changes. Go to the repo you just created on GitHub and check the +[timestamps](../learners/reference.md#timestamp) of the files. How does GitHub +record times, and why? + +::::::::::::::: solution + +## Solution + +GitHub displays timestamps in a human readable relative format (i.e. "22 hours ago" or "three +weeks ago"). However, if you hover over the timestamp, you can see the exact time at which the +last change to the file occurred. + + + +::::::::::::::::::::::::: + +:::::::::::::::::::::::::::::::::::::::::::::::::: + +::::::::::::::::::::::::::::::::::::::: challenge + +## Push vs. Commit + +In this episode, we introduced the "git push" command. +How is "git push" different from "git commit"? + +::::::::::::::: solution + +## Solution + +When we push changes, we're interacting with a remote repository to update it with the changes +we've made locally (often this corresponds to sharing the changes we've made with others). +Commit only updates your local repository. + + + +::::::::::::::::::::::::: + +:::::::::::::::::::::::::::::::::::::::::::::::::: + +::::::::::::::::::::::::::::::::::::::: challenge + +## GitHub License and README files + +In this episode we learned about creating a remote repository on GitHub, but when you initialized +your GitHub repo, you didn't add a README.md or a license file. If you had, what do you think +would have happened when you tried to link your local and remote repositories? + +::::::::::::::: solution + +## Solution + +In this case, we'd see a merge conflict due to unrelated histories. When GitHub creates a +README.md file, it performs a commit in the remote repository. When you try to pull the remote +repository to your local repository, Git detects that they have histories that do not share a +common origin and refuses to merge. + +```bash +$ git pull origin main +``` + +```output +warning: no common commits +remote: Enumerating objects: 3, done. +remote: Counting objects: 100% (3/3), done. +remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0 +Unpacking objects: 100% (3/3), done. +From https://github.com/vlad/planets + * branch main -> FETCH_HEAD + * [new branch] main -> origin/main +fatal: refusing to merge unrelated histories +``` + +You can force git to merge the two repositories with the option `--allow-unrelated-histories`. +Be careful when you use this option and carefully examine the contents of local and remote +repositories before merging. + +```bash +$ git pull --allow-unrelated-histories origin main +``` + +```output +From https://github.com/vlad/planets + * branch main -> FETCH_HEAD +Merge made by the 'recursive' strategy. +README.md | 1 + +1 file changed, 1 insertion(+) +create mode 100644 README.md +``` + +::::::::::::::::::::::::: + +:::::::::::::::::::::::::::::::::::::::::::::::::: + +:::::::::::::::::::::::::::::::::::::::: keypoints + +- A local Git repository can be connected to one or more remote repositories. +- Use the SSH protocol to connect to remote repositories. +- `git push` copies changes from a local repository to a remote repository. +- `git pull` copies changes from a remote repository to a local repository. + +:::::::::::::::::::::::::::::::::::::::::::::::::: + + diff --git a/08-collab-centralized.md b/08-collab-centralized.md new file mode 100644 index 0000000..2a3dec6 --- /dev/null +++ b/08-collab-centralized.md @@ -0,0 +1,64 @@ + +--- +title: Collaborative Version Control - Centralized +teaching: 60 +exercises: 60 +--- + +:::::::::::::::::::::::::::::::::::::::: questions + +- How can I use version control to collaborate with internal collaborators? + +:::::::::::::::::::::::::::::::::::::::::::::::::: + + +::::::::::::::::::::::::::::::::::::::: objectives + +- Understand the basics of collaborative version control with git and Github +- Understand the centralized workflow + +:::::::::::::::::::::::::::::::::::::::::::::::::: + +:::::::::::::::::::::::::::::::::::::::::::::::::: instructor + +Teaching is done as a pair of instructors. +Instructor A acts as the owner of the repository, instructor B as a collaborator (internal or external). + +First we show the centralized workflow all in the browser using Github: + +* instructor A creates an issue (for example create ‘sum’ function) +* instructor B picks up the issue +* Instructor B creates a new branch (good to do this explicitly) +* Instructor B does some reviewable changes (a simple ‘sum’ function) +* Instructor B opens a new pull request. +* Instructor A reviews and approves the PR. +* Instructor B merges the pull request. +* Use Github repo’s insights -> network to visualize what just happened + +:::::::::::::::::::::::::::::::::::::::::::::::::: + +::::::::::::::::::::::::::::::::::::::: challenge + +#### Exercise: Working as a project collaborator (in pairs): +- PERSON A: Create an issue in the repository +- PERSON B: Clone this repository to your system +- PERSON B: Create a new branch +- PERSON B: Make the changes requested in the issue +- PERSON B: Push the changes to the remote repository on GitHub +- PERSON B: Submit a Pull Request, refer to the issue (e.g. "Closes #1") +- PERSON A: Review the Pull Request +- PERSON B: Address the comments +- PERSON A: Approve the Pull Request +- PERSON B: Merge the Pull Request +:::::::::::::::::::::::::::::::::::::::::::::::::: + +::::::::::::::::::::::::::::::::::::::: solution + +:::::::::::::::::::::::::::::::::::::::::::::::::: + + +:::::::::::::::::::::::::::::::::::::::: keypoints +* Git and Github are superpowerful, not just for version control, but as tools for collaborative development +* Do code reviews and be constructive in them! +* Use centralized flow for internal collaborations +:::::::::::::::::::::::::::::::::::::::::::::::::: diff --git a/09-collab-distributed.md b/09-collab-distributed.md new file mode 100644 index 0000000..d2c1276 --- /dev/null +++ b/09-collab-distributed.md @@ -0,0 +1,59 @@ + +--- +title: Collaborative Version Control - Distributed +teaching: 10 +exercises: 60 +--- + +:::::::::::::::::::::::::::::::::::::::: questions + +- How can I use version control to collaborate with external collaborators? + +:::::::::::::::::::::::::::::::::::::::::::::::::: + + +::::::::::::::::::::::::::::::::::::::: objectives + +- Understand distributed workflow and when to use it + +:::::::::::::::::::::::::::::::::::::::::::::::::: + +::::::::::::::::::::::::::::::::::::::: instructor +Teaching is done as a pair of instructors. +Instructor A acts as the owner of the repository, instructor B as a collaborator (internal or external). + +Now we show distributed workflow. All in the browser using Github: + +* Instructor A removes instructor B +* Instructor B now submits an issue +* Instructor A responds to issue asking instructor B to pick it up +* Instructor B forks repo, does some changes, and submits PR +* Instructor A reviews the changes +* Instructor B implements the changes +* Instructor A merges the pull request +* Use Github repo’s insights -> network to visualize what just happened + +:::::::::::::::::::::::::::::::::::::::::::::::::: + +::::::::::::::::::::::::::::::::::::::: challenge + +### Exercise: Working as an external contributor (in pairs) + +- PERSON A: Create an issue in Person B's repository +- PERSON A: Fork the repository to their own (= Person A's) account +- PERSON A: Clone the repository, make changes, push them back to the fork +- PERSON A: Submit a Pull Request from the fork to the original repository +- PERSON B: Make a change in the original repository in the same place as person A's proposed changes +- PERSON A: Solve the merge conflict in the Pull Request +- PERSON B: Review/Approve the Pull Request +- PERSON B: merge the Pull Request +:::::::::::::::::::::::::::::::::::::::::::::::::: + +::::::::::::::::::::::::::::::::::::::: solution + +:::::::::::::::::::::::::::::::::::::::::::::::::: + + +:::::::::::::::::::::::::::::::::::::::: keypoints +* Use distributed flow for external collaborations +:::::::::::::::::::::::::::::::::::::::::::::::::: diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md new file mode 100644 index 0000000..f19b804 --- /dev/null +++ b/CODE_OF_CONDUCT.md @@ -0,0 +1,13 @@ +--- +title: "Contributor Code of Conduct" +--- + +As contributors and maintainers of this project, +we pledge to follow the [The Carpentries Code of Conduct][coc]. + +Instances of abusive, harassing, or otherwise unacceptable behavior +may be reported by following our [reporting guidelines][coc-reporting]. + + +[coc-reporting]: https://docs.carpentries.org/topic_folders/policies/incident-reporting.html +[coc]: https://docs.carpentries.org/topic_folders/policies/code-of-conduct.html diff --git a/LICENSE.md b/LICENSE.md new file mode 100644 index 0000000..7632871 --- /dev/null +++ b/LICENSE.md @@ -0,0 +1,79 @@ +--- +title: "Licenses" +--- + +## Instructional Material + +All Carpentries (Software Carpentry, Data Carpentry, and Library Carpentry) +instructional material is made available under the [Creative Commons +Attribution license][cc-by-human]. The following is a human-readable summary of +(and not a substitute for) the [full legal text of the CC BY 4.0 +license][cc-by-legal]. + +You are free: + +- to **Share**---copy and redistribute the material in any medium or format +- to **Adapt**---remix, transform, and build upon the material + +for any purpose, even commercially. + +The licensor cannot revoke these freedoms as long as you follow the license +terms. + +Under the following terms: + +- **Attribution**---You must give appropriate credit (mentioning that your work + is derived from work that is Copyright (c) The Carpentries and, where + practical, linking to ), provide a [link to the + license][cc-by-human], and indicate if changes were made. You may do so in + any reasonable manner, but not in any way that suggests the licensor endorses + you or your use. + +- **No additional restrictions**---You may not apply legal terms or + technological measures that legally restrict others from doing anything the + license permits. With the understanding that: + +Notices: + +* You do not have to comply with the license for elements of the material in + the public domain or where your use is permitted by an applicable exception + or limitation. +* No warranties are given. The license may not give you all of the permissions + necessary for your intended use. For example, other rights such as publicity, + privacy, or moral rights may limit how you use the material. + +## Software + +Except where otherwise noted, the example programs and other software provided +by The Carpentries are made available under the [OSI][osi]-approved [MIT +license][mit-license]. + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in +the Software without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies +of the Software, and to permit persons to whom the Software is furnished to do +so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + +## Trademark + +"The Carpentries", "Software Carpentry", "Data Carpentry", and "Library +Carpentry" and their respective logos are registered trademarks of [Community +Initiatives][ci]. + +[cc-by-human]: https://creativecommons.org/licenses/by/4.0/ +[cc-by-legal]: https://creativecommons.org/licenses/by/4.0/legalcode +[mit-license]: https://opensource.org/licenses/mit-license.html +[ci]: https://communityin.org/ +[osi]: https://opensource.org diff --git a/config.yaml b/config.yaml new file mode 100644 index 0000000..425cda8 --- /dev/null +++ b/config.yaml @@ -0,0 +1,89 @@ +#------------------------------------------------------------ +# Values for this lesson. +#------------------------------------------------------------ + +# Which carpentry is this (swc, dc, lc, or cp)? +# swc: Software Carpentry +# dc: Data Carpentry +# lc: Library Carpentry +# cp: Carpentries (to use for instructor training for instance) +# incubator: The Carpentries Incubator +carpentry: 'incubator' + +# Overall title for pages. +title: 'Collaborative version control with Git and GitHub' + +# Date the lesson was created (YYYY-MM-DD, this is empty by default) +created: ~ + +# Comma-separated list of keywords for the lesson +keywords: 'Git, GitHub, software, lesson, collaboration, The Carpentries, escience' + +# Life cycle stage of the lesson +# possible values: pre-alpha, alpha, beta, stable +life_cycle: 'pre-alpha' + +# License of the lesson +license: 'CC-BY 4.0' + +# Link to the source repository for this lesson +source: 'https://github.com/esciencecenter-digital-skills/git-lesson' + +# Default branch of your lesson +branch: 'main' + +# Who to contact if there are any issues +contact: 'training@esciencecenter.nl' + +# Navigation ------------------------------------------------ +# +# Use the following menu items to specify the order of +# individual pages in each dropdown section. Leave blank to +# include all pages in the folder. +# +# Example ------------- +# +# episodes: +# - introduction.md +# - first-steps.md +# +# learners: +# - setup.md +# +# instructors: +# - instructor-notes.md +# +# profiles: +# - one-learner.md +# - another-learner.md + +# Order of episodes in your lesson + +episodes: +- 01-basics.md +- 02-setup.md +- 03-create.md +- 04-changes.md +- 05-history.md +- 06-ignore.md +- 07-github.md +- 08-collab-centralized.md +- 09-collab-distributed.md + +# Information for Learners +learners: + +# Information for Instructors +instructors: + +# Learner Profiles +profiles: + +# Customisation --------------------------------------------- +# +# This space below is where custom yaml items (e.g. pinning +# sandpaper and varnish versions) should live + + +url: 'https://esciencecenter-digital-skills.github.io/git-lesson' +lang: en \ No newline at end of file diff --git a/fig/git-checkout.svg b/fig/git-checkout.svg new file mode 100755 index 0000000..6cf55c5 --- /dev/null +++ b/fig/git-checkout.svg @@ -0,0 +1,111 @@ + + + + + + + + .git + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + FILE1.txt + + + + + + + + + + + + + + FILE2.txt + + + HEAD + + HEAD~1 + + HEAD~2 + + 892134f + + f22b25e + + 3a54f76 + + + + + + + + + git checkout HEAD~1or git checkout f22b25e + + + repository + + diff --git a/fig/git-committing.svg b/fig/git-committing.svg new file mode 100755 index 0000000..71b9dca --- /dev/null +++ b/fig/git-committing.svg @@ -0,0 +1,436 @@ + + + +image/svg+xml.git +FILE1.txt +FILE2.txt +git commit +staging area +repository +git add FILE2.txt +git add FILE1.txt + \ No newline at end of file diff --git a/fig/git-freshly-made-github-repo.svg b/fig/git-freshly-made-github-repo.svg new file mode 100755 index 0000000..2d70ffd --- /dev/null +++ b/fig/git-freshly-made-github-repo.svg @@ -0,0 +1,315 @@ + + + +image/svg+xml.git +https://github.com/vlad/planets.git +.git +~/vlad/planets +git add +git commit +staging area +repository + \ No newline at end of file diff --git a/fig/git-restore.svg b/fig/git-restore.svg new file mode 100755 index 0000000..bc44d64 --- /dev/null +++ b/fig/git-restore.svg @@ -0,0 +1,111 @@ + + + + + + + + .git + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + FILE1.txt + + + + + + + + + + + + + + FILE2.txt + + + HEAD + + HEAD~1 + + HEAD~2 + + 892134f + + f22b25e + + 3a54f76 + + + + + + + + + git restore -s HEAD~1or git restore -s f22b25e + + + repository + + diff --git a/fig/git-staging-area.svg b/fig/git-staging-area.svg new file mode 100755 index 0000000..b141c9f --- /dev/null +++ b/fig/git-staging-area.svg @@ -0,0 +1,93 @@ + + + + + + + + .git + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + git add + + + + + + git commit + + staging area + + repository + + diff --git a/fig/git_staging.svg b/fig/git_staging.svg new file mode 100755 index 0000000..3db5b3b --- /dev/null +++ b/fig/git_staging.svg @@ -0,0 +1,675 @@ + + + +image/svg+xmla2129cb + +892134f + +59e230a + +3a54f76 + +43fe423 + + + + branch + +main + +staging area + +git add file2.txt + +git add file1.txt + +HEADHEAD~1HEAD~2 + +git commit + +git restore file1.txt + + + diff --git a/fig/github-change-repo-string.png b/fig/github-change-repo-string.png new file mode 100755 index 0000000..7ffe1bf Binary files /dev/null and b/fig/github-change-repo-string.png differ diff --git a/fig/github-create-repo-01.png b/fig/github-create-repo-01.png new file mode 100755 index 0000000..6dc6bf2 Binary files /dev/null and b/fig/github-create-repo-01.png differ diff --git a/fig/github-create-repo-02.png b/fig/github-create-repo-02.png new file mode 100755 index 0000000..5981881 Binary files /dev/null and b/fig/github-create-repo-02.png differ diff --git a/fig/github-create-repo-03.png b/fig/github-create-repo-03.png new file mode 100755 index 0000000..ebce87d Binary files /dev/null and b/fig/github-create-repo-03.png differ diff --git a/fig/github-find-repo-string.png b/fig/github-find-repo-string.png new file mode 100755 index 0000000..97d339b Binary files /dev/null and b/fig/github-find-repo-string.png differ diff --git a/fig/github-repo-after-first-push.svg b/fig/github-repo-after-first-push.svg new file mode 100755 index 0000000..7003395 --- /dev/null +++ b/fig/github-repo-after-first-push.svg @@ -0,0 +1,483 @@ + + + +image/svg+xml +.gitorigin https://github.com/vlad/planets.git +~/vlad/planets +git add +git commit +staging area +repository +.git +https://github.com/vlad/planets.git +repository +git push origin + \ No newline at end of file diff --git a/fig/merge.svg b/fig/merge.svg new file mode 100755 index 0000000..bc1378c --- /dev/null +++ b/fig/merge.svg @@ -0,0 +1,122 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/fig/motivatingexample.png b/fig/motivatingexample.png new file mode 100755 index 0000000..e9320a9 Binary files /dev/null and b/fig/motivatingexample.png differ diff --git a/fig/phd101212s.png b/fig/phd101212s.png new file mode 100755 index 0000000..c47c428 Binary files /dev/null and b/fig/phd101212s.png differ diff --git a/fig/play-changes.svg b/fig/play-changes.svg new file mode 100755 index 0000000..d1a22e7 --- /dev/null +++ b/fig/play-changes.svg @@ -0,0 +1,175 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/fig/versions.svg b/fig/versions.svg new file mode 100755 index 0000000..96e8cab --- /dev/null +++ b/fig/versions.svg @@ -0,0 +1,247 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/index.md b/index.md new file mode 100644 index 0000000..af66276 --- /dev/null +++ b/index.md @@ -0,0 +1,9 @@ +--- +site: sandpaper::sandpaper_site +--- + +This is a new lesson built with [The Carpentries Workbench][workbench]. + + +[workbench]: https://carpentries.github.io/sandpaper-docs + diff --git a/instructor-notes.md b/instructor-notes.md new file mode 100644 index 0000000..d9a67aa --- /dev/null +++ b/instructor-notes.md @@ -0,0 +1,5 @@ +--- +title: 'Instructor Notes' +--- + +This is a placeholder file. Please add content here. diff --git a/learner-profiles.md b/learner-profiles.md new file mode 100644 index 0000000..434e335 --- /dev/null +++ b/learner-profiles.md @@ -0,0 +1,5 @@ +--- +title: FIXME +--- + +This is a placeholder file. Please add content here. diff --git a/links.md b/links.md new file mode 100644 index 0000000..4c5cd2f --- /dev/null +++ b/links.md @@ -0,0 +1,10 @@ + + +[pandoc]: https://pandoc.org/MANUAL.html +[r-markdown]: https://rmarkdown.rstudio.com/ +[rstudio]: https://www.rstudio.com/ +[carpentries-workbench]: https://carpentries.github.io/sandpaper-docs/ + diff --git a/md5sum.txt b/md5sum.txt new file mode 100644 index 0000000..e09b7c9 --- /dev/null +++ b/md5sum.txt @@ -0,0 +1,20 @@ +"file" "checksum" "built" "date" +"CODE_OF_CONDUCT.md" "c93c83c630db2fe2462240bf72552548" "site/built/CODE_OF_CONDUCT.md" "2024-03-27" +"LICENSE.md" "b24ebbb41b14ca25cf6b8216dda83e5f" "site/built/LICENSE.md" "2024-03-27" +"config.yaml" "94ccf0436981ec70c5970f5c03aae336" "site/built/config.yaml" "2024-06-04" +"index.md" "a02c9c785ed98ddd84fe3d34ddb12fcd" "site/built/index.md" "2024-03-27" +"links.md" "8184cf4149eafbf03ce8da8ff0778c14" "site/built/links.md" "2024-03-27" +"episodes/01-basics.md" "43d28cf161824df2ac6ffe84c9d00363" "site/built/01-basics.md" "2024-09-23" +"episodes/02-setup.md" "7052dbbab41224597dbebbbf31e480fc" "site/built/02-setup.md" "2024-06-26" +"episodes/03-create.md" "8ffe3a4d6908153ab353585655e3e988" "site/built/03-create.md" "2024-09-23" +"episodes/04-changes.md" "fd5ea41bbb5bb63cdeb19218db2fb524" "site/built/04-changes.md" "2024-09-23" +"episodes/05-history.md" "921924687bf19f29563f4610a20c349a" "site/built/05-history.md" "2024-08-05" +"episodes/06-ignore.md" "4aab36d272d749cefe8fa92dd3da8a39" "site/built/06-ignore.md" "2024-06-26" +"episodes/07-github.md" "7d2b813dbda12b02fd4265055d8d89fb" "site/built/07-github.md" "2024-08-05" +"episodes/08-collab-centralized.md" "a9e6873976a4d93242cbc7df16419f33" "site/built/08-collab-centralized.md" "2024-06-26" +"episodes/09-collab-distributed.md" "82b38860c7b6a932a19f3be96b7d9265" "site/built/09-collab-distributed.md" "2024-06-26" +"instructors/instructor-notes.md" "cae72b6712578d74a49fea7513099f8c" "site/built/instructor-notes.md" "2024-03-27" +"learners/reference.md" "1c7cc4e229304d9806a13f69ca1b8ba4" "site/built/reference.md" "2024-03-27" +"learners/setup.md" "5456593e4a75491955ac4a252c05fbc9" "site/built/setup.md" "2024-03-27" +"profiles/learner-profiles.md" "60b93493cf1da06dfd63255d73854461" "site/built/learner-profiles.md" "2024-03-27" +"renv/profiles/lesson-requirements/renv.lock" "1b31c11be0d38181a0a48f9068fa1a09" "site/built/renv.lock" "2024-07-02" diff --git a/reference.md b/reference.md new file mode 100644 index 0000000..ba26b9f --- /dev/null +++ b/reference.md @@ -0,0 +1,8 @@ +--- +title: 'Reference' +--- + +## Glossary + +This is a placeholder file. Please add content here. + diff --git a/renv.lock b/renv.lock new file mode 100644 index 0000000..35c0d64 --- /dev/null +++ b/renv.lock @@ -0,0 +1,31 @@ +{ + "R": { + "Version": "4.4.1", + "Repositories": [ + { + "Name": "carpentries", + "URL": "https://carpentries.r-universe.dev" + }, + { + "Name": "carpentries_archive", + "URL": "https://carpentries.github.io/drat" + }, + { + "Name": "CRAN", + "URL": "https://cran.rstudio.com" + } + ] + }, + "Packages": { + "renv": { + "Package": "renv", + "Version": "1.0.7", + "Source": "Repository", + "Repository": "CRAN", + "Requirements": [ + "utils" + ], + "Hash": "397b7b2a265bc5a7a06852524dabae20" + } + } +} diff --git a/setup.md b/setup.md new file mode 100644 index 0000000..4244a31 --- /dev/null +++ b/setup.md @@ -0,0 +1,54 @@ +--- +title: Setup +--- + +FIXME: Setup instructions live in this document. Please specify the tools and +the data sets the Learner needs to have installed. + +## Data Sets + + +Download the [data zip file](https://example.com/FIXME) and unzip it to your Desktop + +## Software Setup + +::::::::::::::::::::::::::::::::::::::: discussion + +### Details + +Setup for different systems can be presented in dropdown menus via a `spoiler` +tag. They will join to this discussion block, so you can give a general overview +of the software used in this lesson here and fill out the individual operating +systems (and potentially add more, e.g. online setup) in the solutions blocks. + +::::::::::::::::::::::::::::::::::::::::::::::::::: + +:::::::::::::::: spoiler + +### Windows + +Use PuTTY + +:::::::::::::::::::::::: + +:::::::::::::::: spoiler + +### MacOS + +Use Terminal.app + +:::::::::::::::::::::::: + + +:::::::::::::::: spoiler + +### Linux + +Use Terminal + +:::::::::::::::::::::::: +