Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add short Git tutorial #10

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions _quarto.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ book:
- index.qmd
- contents.qmd
- chapters/intro.qmd
- chapters/git.qmd
- summary.qmd
- references.qmd
- acknowledgements.qmd
Expand Down Expand Up @@ -95,6 +96,10 @@ format:
code-copy: true
code-link: false
code-tools: false
code-line-numbers: false
code-annotations: below
highlight-style: monokai
link-external-newwindow: true
footnotes-hover: true
include-after-body: plausible.html

189 changes: 189 additions & 0 deletions chapters/git.qmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,189 @@
---
categories: [beginner, basics]
abstract: "This chapter will is an introduction to Git"
---

# Quick Git Tutorial
Using Git with Quarto adds significant flexibility and enhances the FAIRness of your materials.
Here, we present a quick Git tutorial.

## What Git Can Do

[Git](https://git-scm.com) is a version control system that helps you manage and track the history of your files.
Whether you're working alone or as part of a team, Git offers a range of powerful features that make it easier to collaborate, experiment, and keep your project organized.

Here are some key things Git can do:

**Track Changes:**
Git allows you to record every change made to your project over time.
This means you can see what has been modified, when it was modified, and by whom.

**Version Control:**
With Git, you can manage different versions of your project, making it easily possible to roll back to previous states if something goes wrong.

**Branching and merging:**
Git enables you to create branches, which are independent lines of development.
This lets you work on new features or fixes without affecting the main project.
After developing in a branch, you can merge the changes back into the main project.

**Collaboration:**
Git is designed for collaboration, allowing multiple people to work on the same project simultaneously.
With [GitHub](https://github.com) or other remote repositories, teams can share their work, review changes, and integrate contributions easily.

**Backup:**
By pushing your changes to a remote repository like GitHub, you create a backup of your work that can be accessed from anywhere.

## Using Git: Command Line vs. GUI
Git can be used through the command line, which is a powerful and flexible way to use Git.
This chapter focuses on using Git from the command line, providing you with the core commands needed to manage your project effectively.
However, if you prefer a more visual approach, you can also use Git through Graphical User Interfaces (GUIs), which offer an easier way to handle common Git tasks through point-and-click interactions.
Popular Git GUIs include:

- **GitHub Desktop:** [Download GitHub Desktop](https://github.com/apps/desktop)
- **GitKraken:** [Download GitKraken](https://www.gitkraken.com)

## Installation & Setup

**Install Git:** Download and install Git from [git-scm.com](git-scm.com).

**Configure Git:**
After installation, set up your username and email address using the command line.
these details will be associated with your commits.

```bash
git config --global user.name "Your Name"
```

```bash
git config --global user.email "your.email@example.com"
```

**Rename the default branch:**
By default, Git repositories use master as the main branch.
However, it's now common to use main as the default branch name.
You can rename the branch with the following commands:

```bash
git config --global init.defaultBranch main
```

## Starting with Git
**Initialize a Repository:**
Start tracking your project by turning the folder into a Git repository.
This command creates a hidden `.git` folder that contains all the necessary files for version control.
Before you execute it, you should navigate into your project folder using the command line.

```bash
git init
```

**Check the Status of Your Repository:**
After making changes to your files, check which files have been modified, added, or deleted.
This command helps you see what's going on in your project.

```bash
git status
```

## Working with Files
**Stage Files for Commit:**
Before saving changes to the repository, "stage" them by telling Git which changes to include in the next commit.

```bash
git add <file_name>
```

To stage all changes at once:

```bash
git add .
```

**Commit Your Changes:**
Committing saves a snapshot of your project.
A commit records the current state of your files and allows you to add a message describing what changes you've made.
```bash
git commit -m "Your commit message"
```
Each commit creates a unique ID that allows you to track specific changes or revert to previous states if necessary.

## Viewing Your Project History
**View Commit History:**
Review all the changes made in your repository over time.
The log provides information about each commit, including the author, date, and commit message.

```bash
git log
```

For a simplified view:
```bash
git log --oneline
```

## Working with Branches

**Understanding Branches:**
Branches allow you to work on different features or fixes simultaneously without affecting the main codebase.
The main branch (or master in default repositories) is the default branch where your stable code lives.

**Create a New Branch:**
Develop a new feature or experiment with changes in a separate branch.
This keeps your main branch clean and stable.

```bash
git branch <branch_name>
```

**Switch Between Branches:**
Start working on a branch by switching to it.

```bash
git checkout <branch_name>
```

**Merge Branches:**
After completing work on a branch, merge the changes back into the main branch.
This incorporates all the updates from your feature branch into the stable codebase.

First, switch back to the main branch:

```bash
git checkout main
```

Then merge the changes:

```bash
git merge <branch_name>
```

## Connecting to remote repo

**Add a Remote Repository:**
Link your local repository to a remote one, such as on GitHub.
After creating an empty remote (online) repository, this command connects your local repository to a remote URL.

```bash
git remote add origin <repository_url>
```

**Push Changes:**
Upload your commits to the remote repository on GitHub so others can access your updates.

```bash
git push origin <branch_name>
```

**Pull Changes:**
Download updates from the remote repository to your local repository.

```bash
git pull origin <branch_name>
```

## Summary

Git is a powerful version control system that allows you to track changes, collaborate with others, and manage different versions of your project efficiently.
By understanding how to initialize a repository, stage and commit changes, manage branches, and interact with remote repositories, you can effectively manage your project.
For those looking to dive deeper into Git and explore more advanced features, best practices, and real-world applications, our [Version Control Book](https://lennartwittkuhn.com/version-control-book/) is an excellent resource (we think).
184 changes: 180 additions & 4 deletions chapters/intro.qmd
Original file line number Diff line number Diff line change
@@ -1,9 +1,185 @@
# Introduction
---
categories: [beginner, basics]
abstract: "This chapter will be an introduction to Quarto"
---

This is a book created from markdown and executable code.
# Quarto intro

See @knuth84 for additional discussion of literate programming.
## What is Quarto?

Quarto is an open-source, multi-language, publishing system created by Posit (formerly known as RStudio).
It is designed to enable the creation of dynamic documents, including reports, presentations, websites, books, and more. Quarto builds upon the foundation of RMarkdown, extending its capabilities to support multiple programming languages and various output formats.
Quarto integrates code, text, and media into a single document that can be rendered into various formats.
It supports languages like R, Python, Julia, and JavaScript, making it ideal for scientific writing, data analysis, and technical documentation.
This chapter introduces the basics of Quarto, its features, and how to get started using it for your projects.

### Key Features

- **Multi-language support:**
Quarto allows the integration of code from different programming languages in a single document.

- **Output formats:**
Quarto can generate HTML, PDF, Word documents, presentations (using reveal.js or PowerPoint), and even websites.

- **Integration with RStudio:**
Quarto is deeply integrated with RStudio, making it easy to create and render documents within this IDE.

### Common Use Cases

- **Articles and Reports:**
Quarto is widely used for creating dynamic articles and reports that can include code, figures, and references.

- **Websites:**
You can use Quarto to build entire websites, integrating multiple pages and even blogs.

- **Presentations:**
Quarto allows you to create interactive presentations with support for multimedia content.

- **Books:**
You can use Quarto to write and publish online books, with support for multiple chapters, references, and more.

## Getting started with Quarto

To begin using Quarto, you need to have an appropriate text editor installed.
Quarto supports various editors, including RStudio, Jupyter, Neovim, Visual Studio Code (VS Code), and even plain text editors like e.g. Vim.

### Using Quarto from RStudio

1. **Install RStudio:**
Download and install the latest version of RStudio from the [Posit website](https://posit.co/download/rstudio-desktop/).

2. **Create a Quarto file:**
Open RStudio and navigate to "File" > "New file" > "Quarto Document" to create a new `.qmd` file.

### Rendering Quarto Documents

Quarto documents can be rendered into different formats using either the command line or the RStudio GUI.

- **Preview**
You can preview your Quarto document in a web browser that updates live as you make changes using:

```bash
quarto preview
```

This command opens a live preview of your document in a web browser.
The preview automatically updates each time you save the document.
If you open your quarto file in Rstudio there is also a `render` button at the top of the GUI.

- **Render:**
To render your document without previewing, use:
```bash
quarto render
```
This command generates the final output based on the specified format in the YAML header (e.g., HTML, PDF).

**Where to run these commands**:
Open your terminal or command prompt and navigate to the directory where your Quarto file (e.g., your-document.qmd) is located.

## Markdown Basics

Quarto uses Markdown, a lightweight markup language, for formatting text.
Markdown is easy to learn and widely used in various platforms, including GitHub, Slack, and RStudio.

### Text Formatting

Markdown allows you to easily format text. Here are some common formatting options:

- **Bold:** `**bold text**`
- **Italic:** `*italicized text*`
- **Code:** `` `code` ``
- **Blockquote:** `> blockquote`

### Lists

Markdown supports both ordered and unordered lists:

- **Unordered list:**
```markdown
- Item 1
- Item 2
- Item 3
```

- **Ordered list:**
```markdown
1. First item
2. Second item
3. Third item
```

### Tables

You can create tables in Markdown using the following syntax:

```markdown
| Header 1 | Header 2 |
|----------|----------|
| Cell 1 | Cell 2 |
| Cell 3 | Cell 4 |
```

### Equations

Quarto supports LaTeX syntax for rendering mathematical equations:

- **Inline math:** `$E = mc^{2}$`
- **Display math:**
```latex
$$E = mc^{2}$$
```

### Links and Images

You can easily add links and images in Markdown:

- **Link:** `[Link Text](http://example.com)`
- **Image:** `![Alt Text](http://example.com/image.jpg)`


## Useful features

### YAML Header

The YAML header at the beginning of a Quarto document contains metadata that controls how the document is rendered.
This includes the title, author, date, and output format.

### Example YAML Header
```
---
title: "Document Title"
author: "Your Name"
format: html
theme: default
---
```

### Code Chunks

One of the key features of Quarto is the ability to include executable code chunks within your document.
These chunks can be written in various programming languages and are executed during rendering.

#### Example Code Chunk:

```{r}
1 + 1
# Example Code Chunk
# This is an R code chunk that generates a scatter plot
x <- c(1, 2, 3, 4, 5)
y <- c(2, 4, 1, 3, 5)
plot(x, y, main = "Scatter Plot Example", xlab = "X-Axis", ylab = "Y-Axis")
```

This code will be executed when the document is rendered, and the output (a scatter plot) will be included in the final document.

## Git Integration

Quarto documents (`.qmd` files) are plain text, making them ideal for version control using Git.
You can take advantage of Git's branching and merging capabilities to manage complex document edits and resolve conflicts efficiently.
Check out our [Version Control Book]() for more information about hwo to use Git.

## Conclusion
Quarto is a powerful tool that brings together the best features of Markdown, RMarkdown, and modern programming environments to create dynamic, reproducible documents.
Whether you're writing a research paper, building a website, or preparing a presentation, Quarto provides the tools you need to streamline your workflow and enhance your output.
By mastering the basics covered in this chapter, you'll be well on your way to using Quarto effectively in your own projects.