... | @@ -45,7 +45,7 @@ Command | Effect |
... | @@ -45,7 +45,7 @@ Command | Effect |
|
`git commit` | Move the changes from the staging area to `HEAD` on your local machine
|
|
`git commit` | Move the changes from the staging area to `HEAD` on your local machine
|
|
`git push` | Send the commits on your local machine to the GitLab server
|
|
`git push` | Send the commits on your local machine to the GitLab server
|
|
`git reset <file or directory>` | Un-stage changes to a file that have been git added. Local changes are kept.
|
|
`git reset <file or directory>` | Un-stage changes to a file that have been git added. Local changes are kept.
|
|
`git checkout -- <file or directory>` | Replaces the changes in file with the last content in `HEAD`. Local changes are removed!
|
|
`git checkout -- <file or directory>` | Replaces the changes in the file with the last content in `HEAD`. Local changes are removed!
|
|
` git reset --hard origin/master ` | Replaces **all** local changes with the server version. Local changes are destroyed!
|
|
` git reset --hard origin/master ` | Replaces **all** local changes with the server version. Local changes are destroyed!
|
|
|
|
|
|
|
|
|
... | @@ -61,17 +61,17 @@ Then from the Wikipedia page about GitLab: |
... | @@ -61,17 +61,17 @@ Then from the Wikipedia page about GitLab: |
|
|
|
|
|
For you, as a student, this means you will
|
|
For you, as a student, this means you will
|
|
1. Have at least have one backup of your code in a safe place, provided you push your local changes back to the CS GitLab server,
|
|
1. Have at least have one backup of your code in a safe place, provided you push your local changes back to the CS GitLab server,
|
|
2. Have version history of all your changes, provided your pushed each change to the server,
|
|
2. Have version history of all your changes, provided you've pushed each change to the server,
|
|
2. Learn how to use version control to help prepare you for the working world,
|
|
2. Learn how to use version control to help prepare you for the working world,
|
|
3. Be able to safely submit and track your code, with the over-site of the lecturers and demis.
|
|
3. Be able to safely submit and track your code, with the over-site of the lecturers and demis.
|
|
|
|
|
|
**NOTE:** Always have a number of *safe* and *secure* backups of your code. GitLab should house one of a few copies of your projects.
|
|
**NOTE:** Always have a number of *safe* and *secure* backups of your code. GitLab should house one of a few copies of your projects.
|
|
|
|
|
|
**WARNING!** A secure copy is not public project on GitHub or any other hosting service. Nor is it your friends computer. Please refer to your module guidelines in regard to code sharing and see the plagiarism declaration for your course. Another reference for general Student responsibilities:
|
|
**WARNING!** A secure copy is not a public project on GitHub or any other hosting service. Nor is it your friends computer. Please refer to your module guidelines in regard to code sharing and see the plagiarism declaration for your course. Here is a reference for general Student responsibilities:
|
|
|
|
|
|
[[https://www.sun.ac.za/english/legal/student-discipline]].
|
|
[[https://www.sun.ac.za/english/legal/student-discipline]].
|
|
|
|
|
|
When in doubt, ask your lecturer.
|
|
Otherwise, when in doubt, ask your lecturer.
|
|
|
|
|
|
### Login
|
|
### Login
|
|
GitLab has been set up such that you can log in with your Stellenbosch University credentials.
|
|
GitLab has been set up such that you can log in with your Stellenbosch University credentials.
|
... | @@ -90,7 +90,7 @@ If you have been enrolled in a course that uses GitLab for projects, you should |
... | @@ -90,7 +90,7 @@ If you have been enrolled in a course that uses GitLab for projects, you should |
|
### SSH key Setup
|
|
### SSH key Setup
|
|
Next, we will need to add your SSH key so that you can `clone` a copy of the project repository (or repo for short) to your local PC. We assume you are using a NARGA machine, but these instructions should be applicable for any Linux machine.
|
|
Next, we will need to add your SSH key so that you can `clone` a copy of the project repository (or repo for short) to your local PC. We assume you are using a NARGA machine, but these instructions should be applicable for any Linux machine.
|
|
|
|
|
|
The purpose of the SSH key is for you to authenticate that you are who you are to the server. So **DO NOT** share the key, or your password that you used to lock the key. Keep your password safe, but don't forget it! You can note it down somewhere safe and keep it with you as you will need it to unlock the SSH key in future.
|
|
The purpose of the SSH key is for you to authenticate that you are who you say you are to the server. So **DO NOT** share the key, or your password that you used to lock the key. Keep your password safe, but don't forget it! You should note it down somewhere safe and keep it with you as you will need it to unlock the SSH key in future.
|
|
|
|
|
|
#### Create a new SSH key
|
|
#### Create a new SSH key
|
|
At the below link you will find a guide as to how to create your key.
|
|
At the below link you will find a guide as to how to create your key.
|
... | @@ -144,7 +144,7 @@ Let's get your code from the server to your local machine. |
... | @@ -144,7 +144,7 @@ Let's get your code from the server to your local machine. |
|
|
|
|
|
For example, this is what happens if all goes well:
|
|
For example, this is what happens if all goes well:
|
|
|
|
|
|
````
|
|
```bash
|
|
$ git clone git@git.cs.sun.ac.za:slug/netbot.git
|
|
$ git clone git@git.cs.sun.ac.za:slug/netbot.git
|
|
Cloning into 'netbot'...
|
|
Cloning into 'netbot'...
|
|
remote: Counting objects: 430, done.
|
|
remote: Counting objects: 430, done.
|
... | @@ -152,9 +152,9 @@ Let's get your code from the server to your local machine. |
... | @@ -152,9 +152,9 @@ Let's get your code from the server to your local machine. |
|
remote: Total 430 (delta 52), reused 80 (delta 41)
|
|
remote: Total 430 (delta 52), reused 80 (delta 41)
|
|
Receiving objects: 100% (430/430), 68.86 KiB | 530.00 KiB/s, done.
|
|
Receiving objects: 100% (430/430), 68.86 KiB | 530.00 KiB/s, done.
|
|
Resolving deltas: 100% (215/215), done.
|
|
Resolving deltas: 100% (215/215), done.
|
|
````
|
|
```bash
|
|
|
|
|
|
If you have successfully gotten your code onto your local PC, well done! You should see a new directory within the directory you created with the same name as your project name.
|
|
If you have successfully cloned your code onto your local PC, well done! You should see a new directory within the directory you created with the same name as your project name.
|
|
|
|
|
|
Otherwise, if something went wrong, make a note of the error you encountered and ask a demi for help.
|
|
Otherwise, if something went wrong, make a note of the error you encountered and ask a demi for help.
|
|
|
|
|
... | @@ -162,11 +162,11 @@ Otherwise, if something went wrong, make a note of the error you encountered and |
... | @@ -162,11 +162,11 @@ Otherwise, if something went wrong, make a note of the error you encountered and |
|
Let's create a file in your git directory and see how this change is shown in git.
|
|
Let's create a file in your git directory and see how this change is shown in git.
|
|
|
|
|
|
1. First "cd" into your newly cloned repository. For example following from above:
|
|
1. First "cd" into your newly cloned repository. For example following from above:
|
|
````bash
|
|
```bash
|
|
$ cd ~/git/netbot/
|
|
$ cd ~/git/netbot/
|
|
````
|
|
```
|
|
2. Now create a new empty file using the "touch" command.
|
|
2. Now create a new empty file using the "touch" command.
|
|
````
|
|
```bash
|
|
# First we "ls" to list what is in the directory
|
|
# First we "ls" to list what is in the directory
|
|
$ ls
|
|
$ ls
|
|
|
|
|
... | @@ -176,9 +176,9 @@ Let's create a file in your git directory and see how this change is shown in gi |
... | @@ -176,9 +176,9 @@ Let's create a file in your git directory and see how this change is shown in gi |
|
# Now if we "ls" again we see that fred.txt exists
|
|
# Now if we "ls" again we see that fred.txt exists
|
|
$ ls
|
|
$ ls
|
|
fred.txt
|
|
fred.txt
|
|
````
|
|
```
|
|
3. Now let's ask git what has changed in the repository with "git status":
|
|
3. Now let's ask git what has changed in the repository with "git status":
|
|
````
|
|
```bash
|
|
$ git status
|
|
$ git status
|
|
On branch master
|
|
On branch master
|
|
Your branch is up to date with 'origin/master'.
|
|
Your branch is up to date with 'origin/master'.
|
... | @@ -189,11 +189,11 @@ Let's create a file in your git directory and see how this change is shown in gi |
... | @@ -189,11 +189,11 @@ Let's create a file in your git directory and see how this change is shown in gi |
|
fred.txt
|
|
fred.txt
|
|
|
|
|
|
nothing added to commit but untracked files present (use "git add" to track)
|
|
nothing added to commit but untracked files present (use "git add" to track)
|
|
````
|
|
```
|
|
We see that there is a file called "fred.txt" that is not yet in the index, or in the repository.
|
|
We see that there is a file called "fred.txt" that is not yet in the index, or in the repository.
|
|
4. Let's do as suggested and add the file with `git add fred.txt`.
|
|
4. Let's do as suggested and add the file with `git add fred.txt`.
|
|
5. If we `git status` again we see:
|
|
5. If we type `git status` again we see:
|
|
````
|
|
```bash
|
|
On branch master
|
|
On branch master
|
|
Your branch is up to date with 'origin/master'.
|
|
Your branch is up to date with 'origin/master'.
|
|
|
|
|
... | @@ -201,13 +201,13 @@ Let's create a file in your git directory and see how this change is shown in gi |
... | @@ -201,13 +201,13 @@ Let's create a file in your git directory and see how this change is shown in gi |
|
(use "git reset HEAD <file>..." to unstage)
|
|
(use "git reset HEAD <file>..." to unstage)
|
|
|
|
|
|
new file: fred.txt
|
|
new file: fred.txt
|
|
````
|
|
```
|
|
Now we see that there are local changes that have not been committed, but are being tracked.
|
|
Now we see that there are local changes that have not been committed, but are being tracked.
|
|
|
|
|
|
Do step 2 to 4 again with a new file called "java.txt".
|
|
Do step 2 to 4 again with a new file called "java.txt".
|
|
|
|
|
|
Now when we `git status` we see:
|
|
Now when we `git status` we see:
|
|
````
|
|
```bash
|
|
On branch master
|
|
On branch master
|
|
Your branch is up to date with 'origin/master'.
|
|
Your branch is up to date with 'origin/master'.
|
|
|
|
|
... | @@ -216,7 +216,7 @@ Let's create a file in your git directory and see how this change is shown in gi |
... | @@ -216,7 +216,7 @@ Let's create a file in your git directory and see how this change is shown in gi |
|
|
|
|
|
new file: fred
|
|
new file: fred
|
|
new file: java.txt
|
|
new file: java.txt
|
|
````
|
|
```
|
|
6. Once you have made all the changes you want for a certain piece of work, you can commit them all together after adding them.
|
|
6. Once you have made all the changes you want for a certain piece of work, you can commit them all together after adding them.
|
|
> This is as if you are saying "this is a group of changes that belong together and that I am finished with for now".
|
|
> This is as if you are saying "this is a group of changes that belong together and that I am finished with for now".
|
|
|
|
|
... | @@ -254,12 +254,12 @@ Now that we have added a commit, we need to send those changes back into GitLab. |
... | @@ -254,12 +254,12 @@ Now that we have added a commit, we need to send those changes back into GitLab. |
|
|
|
|
|
### Best practices for your own (and others) sanity
|
|
### Best practices for your own (and others) sanity
|
|
1. Add changes to your commit often.
|
|
1. Add changes to your commit often.
|
|
2. Commit when-ever you step away from your work.
|
|
2. Commit **and** push when-ever you step away from your work.
|
|
3. Try keep all changes in a commit related. The above is more important than this though.
|
|
3. Try keep all changes that are in a commit related. Remember you can create many commits by adding only specific files to a commit, then push all the commits to the GitLab server at once.
|
|
4. Make your commit messages helpful. Short, but descriptive. Remember you can enter a 2nd line of text.
|
|
4. Make your commit messages helpful. Short, but descriptive. Remember you can enter a 2nd line of text.
|
|
|
|
|
|
### Conclusion
|
|
### Conclusion
|
|
You should now be able to manage and contribute to your project! Good luck, and if you spot anything wrong with the Guide, or have suggestions, please log an issue about it [here](https://git.cs.sun.ac.za/Computer-Science/git-beginners/issues).
|
|
You should now be able to manage and contribute to your project! Good luck, and if you spot anything wrong with the wiki, or have suggestions, please log an issue about it [here](https://git.cs.sun.ac.za/Computer-Science/git-beginners/issues).
|
|
|
|
|
|
## Links and Videos
|
|
## Links and Videos
|
|
Link | Description
|
|
Link | Description
|
... | | ... | |