How to Git at Collab Lab
What we’ll cover
There is so much to know, but this should get you started with what you need to know at The Collab Lab!
Repository (repo) - A collection of files, under source control like git.
Remote - The origin repo somewhere online (like GitHub).
Branch - A working copy of the repo. The main branch is the source of truth.
Commit - A set of changes to the repo. HEAD refers to the last commit.
Pull Request (PR) - Documents how/why changes should merge with main. Specific to GitHub—you might also see Merge Request (e.g., GitLab).
terms
Initial commit
Add button
Update text
Add styles
Add tests
Merge branch
Branch
Merge
Initial commit
Add button
Update text
Add styles
Add tests
Merge branch
The Commands
Branching
Switch to an existing branch, or create a new one with the -b option
# Checkout the cool-feature branch
git checkout cool-feature
# Create the new-feature branch
git checkout -b new-feature
git checkout
Staging changes
Staging changes prepares files to be committed.
# Stage a single file
git add ./Button.js
# Stage all files
git add -A
git add
Commiting changes
Takes staged changes and commits them to git. This creates a saved record of changes to the code base.
# Opens an editor to write a message. # Commits staged files
git commit
# Takes an inline message
# Commits staged files
git commit -m "Update heading text"
# Takes an inline message
# Commits staged and tracked files
git commit -am "Add details layout"
git commit
Uploading changes
Takes all commits and uploads them to the remote.
# Sets the upstream remote and sends
# all commits to the remote
git push -u origin cool-feature
# Sends all commits to the upstream
# remote that was set
git push
git push
Getting the latest changes
Gets changes from the remote based on your current branch
# Switch to the main branch
git checkout main
# Get the latest changes for main
git pull
git pull
Pull requests
Merge conflicts
It’s going to be okay!
Resources