GitWorkflow - TheEvergreenStateCollege/upper-division-cs-23-24 GitHub Wiki

Git Workflow

Conceptual View of Git

sequenceDiagram
    participant CleanOnMain
    participant Untracked
    participant Tracked
    participant Staged
    participant Committed
    participant Pushed
    Untracked->>Tracked: `git add <file>`
    Tracked->>Staged: `git add -u .`
    Staged->>Committed: `git commit -m "message"`
    Staged->>Tracked: `git restore <file>`
    Tracked->>Untracked: `git rm --cached <file>`
    Committed->>Pushed: `git push -u origin <branch_name>`
Loading

Standard Workflow

# First make sure you are on `main` and your repo is clean.
cd <repo_dir>/web-24wi/assignments/
git status

# If you see any changes, commit them to the current branch.
git commit -m "<description of your changes>"
# Checkout and create a new branch for your work
git checkout -b <your_github_username>-<weekx>

Add your work and commit it in self-contained changes, usually every few hours or every 10-50 lines of changes, whenever your code compiles or runs cleanly without errors and displays the smallest increase in functionality, or the same functionality with fewer lines (refactoring).

git status
git add <changed_or_new_files>
git commit -m "<describe changes>"
git push -u origin <your_github_username>-<weekx>

Click on the given link to create a Pull Request the first time you push to a new remote branch. On the GitHub website, type a succinct 50 word or less title that includes the assignment name and the week number. You may type any longer description desired in the larger textarea below the title. Choose "Create pull request".

$ git push -u origin annie/frontend
Enumerating objects: 43, done.
Counting objects: 100% (43/43), done.
Delta compression using up to 8 threads
Compressing objects: 100% (40/40), done.
Writing objects: 100% (40/40), 6.55 MiB | 6.92 MiB/s, done.
Total 40 (delta 5), reused 0 (delta 0), pack-reused 0
remote: Resolving deltas: 100% (5/5), completed with 3 local objects.
remote:
remote: Create a pull request for 'annie/frontend' on GitHub by visiting:
remote:      https://github.com/TheEvergreenStateCollege/upper-division-cs/pull/new/annie/frontend
remote:
To github.com:TheEvergreenStateCollege/upper-division-cs.git
 * [new branch]        annie/frontend -> annie/frontend
Branch 'annie/frontend' set up to track remote branch 'annie/frontend' from 'origin'.

New Config

In your laptop the first time you push a config, or on AWS the first time, you may see this message asking you to identify yourself. This is so teammates and other software engineers can identify your changes as belonging to the same person who made your other changes.

This message would look like the following

$ git commit -m "A test commit message to demonstrate the initial config, your message will be different."
[pham-week4 7b17c6a9] Added prisma schema from class on 1/29 and fixed up relations with npx prisma format.
 Committer: Ubuntu <[email protected]>
Your name and email address were configured automatically based
on your username and hostname. Please check that they are accurate.
You can suppress this message by setting them explicitly. Run the
following command and follow the instructions in your editor to edit
your configuration file:

    git config --global --edit

After doing this, you may fix the identity used for this commit with:

    git commit --amend --reset-author

 5 files changed, 221 insertions(+), 18 deletions(-)
 create mode 100644 web-24wi/assignments/ppham/infra/api-server/README.md

Follow the instructions above to add your name and privacy email address.

Pull Before Push

$ git push -u origin pham-week4
To github.com:TheEvergreenStateCollege/upper-division-cs.git
 ! [rejected]          pham-week4 -> pham-week4 (fetch first)
error: failed to push some refs to 'github.com:TheEvergreenStateCollege/upper-division-cs.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

Conflict Resolution

$ git pull origin pham-week4
remote: Enumerating objects: 18, done.
remote: Counting objects: 100% (18/18), done.
remote: Compressing objects: 100% (13/13), done.
remote: Total 18 (delta 9), reused 11 (delta 5), pack-reused 0
Unpacking objects: 100% (18/18), 5.93 KiB | 674.00 KiB/s, done.
From github.com:TheEvergreenStateCollege/upper-division-cs
 * branch              pham-week4 -> FETCH_HEAD
 * [new branch]        pham-week4 -> origin/pham-week4
hint: You have divergent branches and need to specify how to reconcile them.
hint: You can do so by running one of the following commands sometime before
hint: your next pull:
hint:
hint:   git config pull.rebase false  # merge (the default strategy)
hint:   git config pull.rebase true   # rebase
hint:   git config pull.ff only       # fast-forward only
hint:
hint: You can replace "git config" with "git config --global" to set a default
hint: preference for all repositories. You can also pass --rebase, --no-rebase,
hint: or --ff-only on the command line to override the configured default per
hint: invocation.
fatal: Need to specify how to reconcile divergent branches.
⚠️ **GitHub.com Fallback** ⚠️