git.md 3.43 KB
Newer Older
Hui Wang's avatar
Hui Wang committed
1
[[Home]](index) [[Mesh Edit]](./meshedit/overview) [[Path Tracer]](./pathtracer/overview) [[Animation]](./animation/overview)
Hui Wang's avatar
Hui Wang committed
2

TheNumbat's avatar
TheNumbat committed
3
---
Hui Wang's avatar
Hui Wang committed
4

allai5's avatar
allai5 committed
5
# Github Setup
TheNumbat's avatar
TheNumbat committed
6
7
8
9

Please do not use a public github fork of this repository! We do not want solutions to be public. You should work in your own private repo.
We recommended creating a mirrored private repository with multiple remotes. The following steps go over how to achieve this.

Hui Wang's avatar
Hui Wang committed
10
The easiest (but not recommended) way is to download a zip from GitHub and make a private repository from that. The main disadvantage with this is that whenever there is an update to the base code, you will have to re-download the zip and manually merge the differences into your code. This is a pain, and you already have a lot to do, so instead, let `git` take care of this cumbersome "merging-updates" task:
TheNumbat's avatar
TheNumbat committed
11
12

1. Clone Scotty3D normally
Hui Wang's avatar
Hui Wang committed
13
    - `git clone http://dalab.se.sjtu.edu.cn/gitlab/courses/scotty3d.git`
TheNumbat's avatar
TheNumbat committed
14
15
16
17
18
19
20
21
22

2. Create a new private repository (e.g. `MyScotty3D`)
    - Do not initialize this repository - keep it completely empty.
    - Let's say your repository is now hosted here: `https://github.com/your_id/MyScotty3D.git`

3. Ensure that you understand the concept of `remote`s in git.
    - When you clone a git repository, the default remote is named 'origin' and set to the URL you cloned from.
    - We will set the `origin` of our local clone to point to `MyScotty3D.git`, but also have a remote called `sourcerepo` for the public `Scotty3D` repository.

allai5's avatar
allai5 committed
23
4. Now go back to your clone of Scotty3D. This is how we add the private remote:
Hui Wang's avatar
Hui Wang committed
24
    - Since we cloned from the `courses/scotty3d.git` repository, the current value of `origin` should be `http://dalab.se.sjtu.edu.cn/gitlab/courses/scotty3d.git`
TheNumbat's avatar
TheNumbat committed
25
26
        - You can check this using `git remote -v`, which should show:
            ```
Hui Wang's avatar
Hui Wang committed
27
28
            origin      http://dalab.se.sjtu.edu.cn/gitlab/courses/scotty3d.git (fetch)
            origin      http://dalab.se.sjtu.edu.cn/gitlab/courses/scotty3d.git (push)
TheNumbat's avatar
TheNumbat committed
29
30
31
32
33
34
            ```
    - Rename `origin` to `sourcerepo`:
        - `git remote rename origin sourcerepo`
    - Add a new remote called `origin`:
        - `git remote add origin https://github.com/your_id/MyScotty3D.git`
    - We can now push the starter code to our private copy:
TheNumbat's avatar
TheNumbat committed
35
        - `git push origin -u main`
TheNumbat's avatar
TheNumbat committed
36

TheNumbat's avatar
TheNumbat committed
37
38
5. Congratulations! you have successfully _mirrored_ a git repository with all past commits intact. 

Hui Wang's avatar
Hui Wang committed
39
Now, let's see why this setup may be useful: say we start doing an assignment and commit regularly to our private repo (our `origin`). Then the CS403 staff push some new changes to the Scotty3D skeleton code that we want to pull in. But, we don't want to mess up the changes we've added to our private copy. Here's where git comes to the rescue:
TheNumbat's avatar
TheNumbat committed
40
41

1. Commit all local changes to your `origin`.
Max Slater's avatar
Max Slater committed
42
2. Run `git pull sourcerepo main` - this pulls all the changes from `sourcerepo` into your local copy.
TheNumbat's avatar
TheNumbat committed
43
44
45
46
    - If there are files with changes in both `origin` and `sourcerepo`, git will attempt to automatically merge the updates. Git may create a "merge" commit for this.
    - Unfortunately, there may be conflicts. Git will handle as many merges as it can, then then tell you which files have conflicts that need manual resolution. You can resolve the conflicts in your text editor and create a new commit to complete the `merge` process.
3. After you have completed the merge, you now have all the updates locally. Push to your private origin to publish changes there too:
    - `git push origin main`
TheNumbat's avatar
TheNumbat committed
47