Git Guidance Reference

CS 373 — Software Engineering • Summer 2026
Canvas is the source of truth.
Use these pages as setup and workflow guidance. Official course policies, assignments, and deadlines are posted in Canvas.
Return to: Course home

Resource Pages

Start Here
Set up UTCS access, Python, Git, coverage, and required tools.
Git Guidance
Configure Git and practice common repository workflows.
Unix/Linux Commands
Searchable command reference for working in the Linux shell.

Overview

Git is a powerful tool for tracking changes in your code and collaborating with others. GitLab is the website where your remote repositories are hosted. Open a terminal, create a folder named gitlab, and work through the steps below.

Configuration and Basic Repo Workflow

  1. Configuring Git Replace John Galt and jgalt@example.com with your name and email.
    $ git config --global user.name "John Galt"
    $ git config --global user.email jgalt@example.com
    $ git config --global push.default simple
    $ git config --global color.ui true
    $ git config --global init.defaultBranch main

    If you are using macOS or Linux:

    $ git config --global core.autocrlf input

    If you are using Windows:

    $ git config --global core.autocrlf true

    Note: The $ marks the terminal prompt. It is not part of the command.

  2. Checking the Git configuration
    $ git config -l
    user.name=John Galt
    user.email=jgalt@example.com
    push.default=simple
    color.ui=true
    init.defaultBranch=main
    core.autocrlf=input
    ...
  3. Creating a private code repo on GitLab
    • Log in to your GitLab account.
    • Click New project or Create blank project.
    • Choose a project name, such as my-repo.
    • Select the visibility level as private.
    • Select initialize repository with a README.
    • Click Create project.
  4. Cloning a code repo to your local machine
    $ git clone https://gitlab.com/jgalt/my-repo.git

    This clones the private code repo, my-repo, to your local machine.

  5. Alternative way to create and connect a repo

    Before pushing, create an empty project named another-repo on GitLab without initializing it with a README.

    The example below uses touch README.md, which works in Git Bash, macOS, Linux, or WSL. In Windows PowerShell, use New-Item README.md -ItemType File. In Windows Command Prompt, use type nul > README.md.

    $ cd ..
    $ mkdir another-repo
    $ cd another-repo
    $ touch README.md
    $ git init -b main
    $ git remote add origin https://gitlab.com/jgalt/another-repo.git
    $ git add README.md
    $ git commit -m 'first commit'
    $ git push -u origin main

    This creates the local repo another-repo, connects it to the empty GitLab project, and pushes the first commit.

  6. Syncing with a repo
    $ cd my-repo
    $ git pull
    Already up-to-date.
  7. Checking the status of a repo
    $ cd my-repo
    $ git status
    # On branch main
    nothing to commit, working tree clean
  8. Adding to a repo
    $ cd ..
    $ cd my-repo
    $ git add Foo.py
    $ git add Bar.py
    $ git commit -m "another commit"
    $ git push origin main
    # or simply:
    $ git push
  9. Undo adding to a repo before committing
    $ git restore --staged <filename>
  10. Undo a commit
    $ git reset --soft HEAD~1

    This undoes the most recent local commit but keeps the changes staged. Use this only for commits that have not been pushed. If you already pushed the commit, ask before rewriting history, or use git revert instead.

Forking and Branching

  1. Forking a repo
    • Get the HTTPS link of the repo you need to fork, such as https://gitlab.com/fareszf/cs373-collatz.git.
    • Click the fork button.
    • When prompted, select a namespace to fork the project.

    Note: After forking, the name and HTTPS link of the repo will be the same as the cloned repo, such as https://gitlab.com/YourGitLabID/cs373-collatz.git.

    To rename the repo from cs373-collatz to collatz and change the HTTPS link to https://gitlab.com/YourGitLabID/collatz.git:

    • Select the repo cs373-collatz.
    • Go to the bottom of the left menu and click Settings.
    • Click Advanced and go to rename repository.
  2. Creating a local dev branch
    $ cd ..
    $ cd another-repo
    
    $ git branch dev
    $ git checkout dev
    # or combine both commands:
    $ git checkout -b dev
    
    Switched to a new branch 'dev'
    
    $ git status
    On branch dev
    
    No commits yet
    
    nothing to commit (create/copy files and use "git add" to track)
    
    $ touch newfile
  3. Listing all local branches and highlighting the current branch
    $ git branch
    * dev
      main
  4. Pushing to a remote, not-yet-created dev branch
    $ git add .
    $ git commit -m "Pushing to remote non-existing branch"
    $ git push origin dev
  5. Merging dev branch with main branch
    $ git checkout main
    $ git merge dev

    If there are merge conflicts, resolve them, then run git add and git commit.

  6. Pushing after merging dev with main
    $ git push

Undo with Git

For more examples, see How to undo almost anything with Git.