Git & GitHub Guide#


1 Installation & Initial Configuration#

1.1 Installation#

MacOS (Requires Homebrew)#

brew install git

Linux (Debian/Ubuntu)#

apt-get install git

Verify Version#

git --version

1.2 Global Configuration#

# Set Identity
git config --global user.name "Marc Ouellet"
git config --global user.email "marc.ouellet@gmail.com"

# Set Default Branch to match GitHub (main)
git config --global init.defaultBranch main

# Verify Settings
git config --global user.name
git config --global user.email

# Common Alias
git config --global alias.s "status"

2 The Collaborative Workflow#

To work simultaneously on the same project without overwriting each other, you should follow a specific cycle for every work session. This process ensures that everyone stays in sync while moving one step at a time.

### Check status
git fetch origin
git status
### The Opening Move: Pull
# Pull the content
git pull origin main
### The Work Phase: Edit and Create and commit
# Pull the content
git add . && git commit -m 'Comments'

Warning: If files were deleted

### If files were deleted
# This stages the fact that the files were deleted
git add . 
# This commits the removal to your local history
git commit -m "Remove test1.txt and test2.txt" 
### The Closing Move: Push
# Push the content to GitHub
git push origin main
### On the second computer
# Pull the content
git pull origin main

3 Advanced & Recovery#

3.1 Reposition Head (Force push)#

git push origin HEAD --force

3.2 Hard Reset to previous version#

git reset --hard HEAD^

4 Local Workflow#

4.1 Initialize & Stage#

Start Git in current folder#

git init
git status

Add filter for sensitive files#

nano .gitignore

Add files to staging#

git add .               # All files
git add <filename>      # Individual file

5 Commits & Version Control#

Create a version#

git commit -m 'Initial commit'

Amend the last commit#

git commit -m 'New message' --amend

Reset staging area (unstage)#

git reset .

Discard changes in working directory#

git checkout -- .

History#

git log
# List last 5 commits
git log --oneline -n 5

5.2 Restoring Versions#

# Checkout specific commit or file from commit
git checkout <commit-hash>
git checkout <commit-hash> <filename>

6 Branches & Merging#

6.1 Visualization#

# Pro-level branch graph
git log --oneline --graph --all --decorate

6.2 Branching Workflow#

Create and switch#

git branch FEATUREBRANCHNAME
git checkout FEATUREBRANCHNAME

Merge into main#

git checkout main
git merge FEATUREBRANCHNAME -m 'Merge feature'

7 GitHub Integration#

7.1 SSH Authentication#

# 1. Generate Key
ssh-keygen -t ed25519

# 2. Copy Public Key to GitHub (Settings > SSH Keys)
cat ~/.ssh/id_ed25519.pub

# 3. Test Connection
ssh -T git@github.com

7.2 Remote Repository Management#

# Link local to remote
git remote add origin git@github.com:marcoue/GenDash.app.git
git branch -M main

Pushing & Pulling#

git push -u origin main   # First push
git push origin main      # Subsequent pushes
git pull origin main      # Pull updates

Cloning#

git clone git@github.com:marcoue/inuvik.git

Verify Remote#

## Check which remote servers (like GitHub, GitLab, or a private server) your local repository is connected to
git remote -v
#similar to git status but to check the remote vs the local version for safety
git fetch
## Save pull - Does a merge
git pull
## Full pull - Overwrites all local files
git reset --hard origin/main
## Check which remote servers (like GitHub, GitLab, or a private server) your local repository is connected to
git remote -v
# Remove a previously synched folder from Git and GitHub
git rm -r --cached public/

7.3 Override all files of a folder with Github content#


## Update local records
git fetch origin
## Force-align with GitHub
git reset --hard origin/main
## Delete local untracked files
git clean -fd