Skip to content

Commit

Permalink
Fixed issue #30, changed 'protip'
Browse files Browse the repository at this point in the history
  • Loading branch information
Niek Bongers committed Aug 21, 2024
1 parent a8b4a76 commit 76bc215
Showing 1 changed file with 16 additions and 16 deletions.
32 changes: 16 additions & 16 deletions index.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ Effective use of git includes two components: local software to manage the files
In this course, we will primarily use Git GUI as the client. It is a simple client that is included with Git itself, and is language-agnostic. There are more graphical clients as well, including one integrated into RStudio itself, but these clients are outside the scope of this course. Note that Git is language-agnostic, and we will be using it with both R and Python, so it's best to learn the language-neutral GUI, rather than an R-specific GUI.

```{block, type="alert alert-info"}
**Protip**: For those who are comfortable with working from the Linux terminal, the command line client is often the most efficient choice. Knowing how to use git from the command line is also useful when working on cloud virtual machines/servers for big data processing. So in pro-tip boxes like this you will find command line equivalents to the GUI actions we will perform. Choose whichever way you find the most convenient for yourself.
**Tip**: For those who are comfortable with working from the Linux terminal, the command line client is often the most efficient choice. Knowing how to use git from the command line is also useful when working on cloud virtual machines/servers for big data processing. So in pro-tip boxes like this you will find command line equivalents to the GUI actions we will perform. Choose whichever way you find the most convenient for yourself.
In the [next tutorial](https://geoscripting-wur.github.io/Intro2Linux/) we will introduce you to more command line commands.
Expand All @@ -205,7 +205,7 @@ Launch a program called *Git GUI* (e.g. from the *Applications* → *Programming
```{block, type="alert alert-info"}
**Note**: External users should [download git](https://git-scm.com/download/) and install it to obtain Git GUI.
**Protip**: You can launch Git GUI from the terminal with `git gui`.
**Tip**: You can launch Git GUI from the terminal with `git gui`.
```

2. *Create an SSH key pair*
Expand All @@ -219,7 +219,7 @@ Once done, you will see your new public key:
![SSH public key generated](figs/git_gui_sshkey.png)

```{block, type="alert alert-info"}
**Protip**: From the command line you generate a key pair by running `ssh-keygen -t rsa -b 4096`. In both cases, by default the public key is stored in the file `~/.ssh/id_rsa.pub` (where `~` indicates the user's home directory).
**Tip**: From the command line you generate a key pair by running `ssh-keygen -t rsa -b 4096`. In both cases, by default the public key is stored in the file `~/.ssh/id_rsa.pub` (where `~` indicates the user's home directory).
```

### Account setup
Expand Down Expand Up @@ -286,15 +286,15 @@ You will end up in an empty Git GUI window:
```

```{block, type="alert alert-info"}
**Protip**: From the terminal, `cd` into the directory you want to clone into, and run `git clone <url>`, e.g. `git clone [email protected]:you001/example.git`. The repository will be cloned into a subdirectory with a matching name. This is much faster than using any GUI!
**Tip**: From the terminal, `cd` into the directory you want to clone into, and run `git clone <url>`, e.g. `git clone [email protected]:you001/example.git`. The repository will be cloned into a subdirectory with a matching name. This is much faster than using any GUI!
```

9. *Tell Git who you are*

Before you start using Git, you should tell it what your name and email address is. You need to do that only once per Git installation. You should go to *Edit**Options...* and fill out the *Global (All Repositories)* options *User Name* and *Email Address*. These will be displayed on GitLab.

```{block, type="alert alert-info"}
**Protip**: To set your user name and email from the command line:
**Tip**: To set your user name and email from the command line:
git config --global user.name "Your Name"
git config --global user.email [email protected]
Expand All @@ -312,7 +312,7 @@ Once you are done, go back to Git GUI. If you closed the window, you can get bac
![Changes pending in Git GUI](figs/git_gui_changes.png)

```{block, type="alert alert-info"}
**Protip**: To see a list of files with pending changes from the command line, use `git status` while in a git repository. To see what exactly changed in each of these files, use `git diff`.
**Tip**: To see a list of files with pending changes from the command line, use `git status` while in a git repository. To see what exactly changed in each of these files, use `git diff`.
```

At the top left corner, the *Unstaged Changes* panel, you can see all the files that changed in your workspace. If you click on the **name** of the file, the main panel will show you what changed since the last commit. Unless it is a non-text (data) file, in which case it will just note that something has changed. **Note**: Git is very efficient with storing changes in text files: these *diff* files are all it stores internally, it does not copy the whole file on each commit. However, it does not deal efficiently with non-text files, and thus you should limit the amount and size of such files as much as possible.
Expand All @@ -322,7 +322,7 @@ If you click on the **icon** of the file in the *Unstaged Changes* panel, the fi
Remember: clicking the **name** of the file shows the changes you made, clicking the **icon** of the file stages or unstages the change!

```{block, type="alert alert-info"}
**Protip**: To stage a change from the command line, use `git add path/to/file.ext` where `path/to/file.ext` is the file you want to stage. To unstage, use `git reset HEAD path/to/file.ext`.
**Tip**: To stage a change from the command line, use `git add path/to/file.ext` where `path/to/file.ext` is the file you want to stage. To unstage, use `git reset HEAD path/to/file.ext`.
If you have files that you don't want git to track, you can add them into the `.gitignore` file. It could be the name of a file, a directory, a wildcard (e.g. `*.pdf`), or any combination of these. To list several, put them on separate lines.
```
Expand All @@ -336,13 +336,13 @@ If it is the first time you use Git GUI to make a commit, and you haven't filled
Next press the *Commit* button and your commit will be saved locally. A commit is like a saved state: you are always able to roll back the contents of your tracked files to the state they were in when you committed the changes.

```{block, type="alert alert-info"}
**Protip**: To commit a change from the command line, use `git commit`. If you want to stage all tracked and changed files and commit, use `git commit -a`. To include a message with your commit you can use the commit command with a `-m` flag, for example: `git commit -m "added plots to webapp" `.
**Tip**: To commit a change from the command line, use `git commit`. If you want to stage all tracked and changed files and commit, use `git commit -a`. To include a message with your commit you can use the commit command with a `-m` flag, for example: `git commit -m "added plots to webapp" `.
```

In the case you made a mistake (a mistake in the message, forgot to stage something, etc.), you can press the *Amend Last Commit* button and get right back to where you were when you made the last commit; but use this functionality very sparingly, as it does not work with changes that have already been pushed to GitLab.

```{block, type="alert alert-info"}
**Protip**: To amend the last commit from the command line, use `git commit \-\-amend`.
**Tip**: To amend the last commit from the command line, use `git commit \-\-amend`.
```

10. *Push changes to the server*
Expand All @@ -352,7 +352,7 @@ Press the *Push* button, and confirm the push, to send all your changes to your
![GitLab repository with content](figs/GitLab-repository.png)

```{block, type="alert alert-info"}
**Protip**: To push changes from the command line, use `git push`.
**Tip**: To push changes from the command line, use `git push`.
```

11. *Pull changes from the server*
Expand All @@ -364,7 +364,7 @@ If there are any changes on GitLab that are not on your local copy yet, in Git G
To attempt to apply the changes, go to *Merge**Local Merge...*. If all goes well, the changes will be applied.

```{block, type="alert alert-info"}
**Protip**: To do a fetch and merge together the command line, use `git pull`.
**Tip**: To do a fetch and merge together the command line, use `git pull`.
```

There may be cases where files go out of sync in incompatible ways, however, like two people editing one file at the same time. In that case you may hit a *merge conflict*. It is best to try to avoid them. In case it happens, you need to go through the conflicting files in a text editor and edit them by hand, keeping the parts of the files you need. The conflicting parts will be in between lines of of `>>>>` and `<<<<` symbols. Once you remove the parts you don't need (including the separators), you can solve the conflict by committing the changes.
Expand All @@ -376,7 +376,7 @@ Now we know how to work with Git and GitLab for our personal work, and how to co
A fork is your own personal copy of someone else's repository. GitLab allows you to fork any public repository. You want to make forks whenever you want to edit code but do not have direct commit rights.

```{block, type="alert alert-info"}
**Protip**: In fact, if you click the edit button on a file on GitLab and do changes to a repository that you don't have the rights to write into, GitLab will helpfully make a fork for you, followed by a proposal to make a merge request for your changes.
**Tip**: In fact, if you click the edit button on a file on GitLab and do changes to a repository that you don't have the rights to write into, GitLab will helpfully make a fork for you, followed by a proposal to make a merge request for your changes.
```

12. *Fork a repository*
Expand All @@ -402,29 +402,29 @@ This will show you all the changes you have made, and if that is what you want t
Then it's up to the upstream developers to perform a code review and either accept or reject the pull request in the end.

```{block, type="alert alert-info"}
**Protip**: For code review, GitLab also has special tools. If you look at the *Changes* tab of a merge request, you will see that you can press a bubble button next to any line of code and write a comment about it. Once finished, there is a "Submit review" button at the bottom to send all comments at once.
**Tip**: For code review, GitLab also has special tools. If you look at the *Changes* tab of a merge request, you will see that you can press a bubble button next to any line of code and write a comment about it. Once finished, there is a "Submit review" button at the bottom to send all comments at once.
```

### Other Git GUI functionality

You might run into a situation when you have made changes in tracked files, but do not want to keep some of the changes. You can revert one file by selecting it in Git GUI, then clicking *Commit**Revert changes*.

```{block, type="alert alert-info"}
**Protip**: The command line equivalent is `git checkout \-\- path/to/file.ext`, or if you want to reset all changed files, `git reset \-\-hard`.
**Tip**: The command line equivalent is `git checkout \-\- path/to/file.ext`, or if you want to reset all changed files, `git reset \-\-hard`.
```

Git GUI not only provides a way to make, push and pull commits, but also to visualise the commit history of your repository in a tree graph. Go to *Repository**Visualise Master's History* to see it. For larger and more complex projects with lots of contributors and merges, it might look like some sort of a subway map:

![Git GUI history (gitk)](figs/git_gui_gitk.png)

```{block, type="alert alert-info"}
**Protip**: The command line equivalent is `git log`.
**Tip**: The command line equivalent is `git log`.
```

The history view also allows you to reset the state of the repository to any previous commit by using the context menu. Note, however, that you can only push if you are on the latest commit. So the easiest way to revert changes is to copy over the files to a temporary directory outside of git, reset back, and move the files back into your repository.

```{block, type="alert alert-info"}
**Protip**: A few more options are available from the command line. `git revert <commit>` will undo changes from a given commit, where `<commit>` is the commit ID (you can get commit IDs from `git log`, they look like a long string of letters and numbers). `git checkout <commit> \-\- path/to/file.ext` will reset a single file to the state it was at the given commit.
**Tip**: A few more options are available from the command line. `git revert <commit>` will undo changes from a given commit, where `<commit>` is the commit ID (you can get commit IDs from `git log`, they look like a long string of letters and numbers). `git checkout <commit> \-\- path/to/file.ext` will reset a single file to the state it was at the given commit.
```

You can also browse the history of a repository from your Git hosting service, and GitHub/GitLab even allow editing files from a web interface.
Expand Down

0 comments on commit 76bc215

Please sign in to comment.