Source Code Hosting

  1. Follow the instructions on the hosting site to create a project if you do not already have one.

  2. Clone / check out the project to your local machine. Most sites offer a button on the project page to provide the URL for cloning. Using https is generally recommended over ssh. Be sure to add your account name to the URL. The URLs provided are meant for read-only access, so you will not be able to push changes unless you use add your account name.

    Figure 32.1. Getting the Gitlab Clone URL

    Getting the Gitlab Clone URL

    shell-prompt: git clone
    Cloning into 'example'...
    Password for '': 
    remote: Enumerating objects: 3, done.
    remote: Counting objects: 100% (3/3), done.
    remote: Compressing objects: 100% (2/2), done.
    remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
    Receiving objects: 100% (3/3), done.
  3. Add files to the project by copying them from another directory or creating them in a text editor or other tool.

    shell-prompt: cd example
    shell-prompt: cp ~/Project-files/*.txt .
    shell-prompt: ape example.c
    shell-prompt: git add *.txt example.c
  4. Frequently commit and push changes to the files. This should generally be done when things are in a working state. Make small changes, perform integration testing (testing the small changes even though the program is far from complete), and then commit and push them so that they will be safe from accidental deletion, disk failure, computer theft, etc.

    shell-prompt: git status
    On branch main
    Your branch is up to date with 'origin/main'.
    Untracked files:
      (use "git add <file>..." to include in what will be committed)
    nothing added to commit but untracked files present (use "git add" to track)
    shell-prompt: git add example.c input*.txt
    shell-prompt: git status
    On branch main
    Your branch is up to date with 'origin/main'.
    Changes to be committed:
      (use "git restore --staged <file>..." to unstage)
            new file:   example.c
            new file:   input1.txt
            new file:   input2.txt
    shell-prompt: git commit -a -m 'Add example.c and test input files'
    [main 288b9b4] Add example.c and test input files
     3 files changed, 40 insertions(+)
     create mode 100644 example.c
     create mode 100644 input1.txt
     create mode 100644 input2.txt
    shell-prompt: git push
    Enumerating objects: 5, done.
    Counting objects: 100% (5/5), done.
    Delta compression using up to 4 threads
    Compressing objects: 100% (3/3), done.
    Writing objects: 100% (4/4), 640 bytes | 640.00 KiB/s, done.
    Total 4 (delta 0), reused 0 (delta 0), pack-reused 0
       03105ab..288b9b4  main -> main