Git, GitLab, and SSH Setup Documentation¶
Overview¶
This document covers the process of setting up Git, connecting to GitLab using SSH authentication, and successfully pushing a local Fab Academy repository to GitLab.
Initial Setup: Adding .DS_Store to .gitignore¶
What We Did¶
Added .DS_Store files to .gitignore to prevent macOS system files from being tracked by Git.
Commands Used¶
echo ".DS_Store" >> .gitignore
echo "**/.DS_Store" >> .gitignore
Why¶
.DS_Storefiles are macOS system files that store folder display settings- They're created automatically by macOS in every folder
- They shouldn't be tracked in version control as they're system-specific and not part of the project
First Push Attempt: Upstream Branch Issue¶
What Happened¶
When trying to push with git push, we got an error:
fatal: The current branch main has no upstream branch.
What We Did¶
Used the command to set the upstream branch:
git push -u origin main
git push --set-upstream origin main
Why¶
-uis shorthand for--set-upstream- This creates a tracking relationship between your local
mainbranch and the remoteorigin/mainbranch - After setting this once, future pushes only need
git push - The upstream connection tells Git where to push and pull from by default
Authentication: Switching from HTTPS to SSH¶
Initial Problem¶
Authentication failed with HTTPS, requiring a Personal Access Token.
What We Did¶
-
Verified existing remote:
Output showed HTTPS URL:git remote -vorigin https://gitlab.fabcloud.org/dorian-fritze/fab-academy-2026.git -
Found existing SSH key:
Discoveredls -la ~/.sshid_ed25519already existed (when prompted to overwrite, we chose no) -
Retrieved public key:
cat ~/.ssh/id_ed25519.pub -
Added SSH key to GitLab:
- Navigated to: Profile → Preferences → SSH Keys
-
Added the public key from step 3
-
Changed remote URL to SSH:
git remote set-url origin git@gitlab.fabcloud.org:dorian-fritze/fab-academy-2026.git
Why SSH Instead of HTTPS¶
- More secure: Uses cryptographic key pairs instead of passwords/tokens
- More convenient: No need to enter credentials for each push/pull
- Better for Fab Academy: Standard practice for frequent Git operations
- No token management: Don't need to create, store, or refresh access tokens
SSH vs Personal Access Token¶
- SSH Key: Cryptographic authentication using public/private key pairs
- URL format:
git@gitlab.fabcloud.org:username/repo.git -
Setup once, use forever (until revoked)
-
Personal Access Token: Password-like string for HTTPS
- URL format:
https://gitlab.fabcloud.org/username/repo.git - Must be entered or stored in credential manager
- Can expire or need rotation
Merging Remote and Local Repositories¶
What Happened¶
When pushing, we got an error:
! [rejected] main -> main (fetch first)
error: failed to push some refs
hint: Updates were rejected because the remote contains work that you do
hint: not have locally.
What We Did¶
-
Pulled remote changes with merge strategy:
git pull origin main --allow-unrelated-histories --no-rebase -
Completed the merge message in vim:
- Pressed
Esc - Typed
:wq -
Pressed
Enter -
Pushed merged changes:
git push
Why This Happened¶
- GitLab repository had files that weren't in the local repository
- Local repository had files that weren't on GitLab
- Git saw these as two unrelated histories
Why These Flags¶
--allow-unrelated-histories: Allows Git to merge two repositories that don't share a common commit history--no-rebase: Uses merge strategy instead of rebase (creates a merge commit)
Vim Editor Navigation¶
Esc: Enter command mode:wq: Write (save) and quit:q!: Quit without saving (if needed)
Cleaning Up Deleted Files¶
What Happened¶
Google Docs HTML files and associated assets needed to be removed from Git tracking.
What We Did¶
-
Removed individual file:
git rm "public/assignments/week01/10-Git commands-&-how-to-make-shortcuts - Google Docs.html" -
Removed entire folder recursively:
git rm -r "public/assignments/week01/10-Git commands-&-how-to-make-shortcuts - Google Docs_files" -
Committed deletions:
git commit -m "Remove Google Docs files" -
Pushed changes:
git push
Why Quotes and -r Flag¶
- Quotes: Necessary when filenames contain spaces or special characters like
& -rflag: "Recursive" - removes entire directory and all contents
Key Git Commands Summary¶
| Command | Purpose |
|---|---|
git status |
Check current state of repository |
git add <file> |
Stage files for commit |
git commit -m "message" |
Commit staged changes with message |
git push |
Push commits to remote repository |
git pull |
Fetch and merge remote changes |
git remote -v |
View remote repository URLs |
git remote set-url |
Change remote repository URL |
git rm <file> |
Remove file from Git tracking |
git rm -r <folder> |
Remove folder recursively |
Common Issues and Solutions¶
Spaces in Filenames¶
Problem: Commands fail with spaces in filenames
Solution: Use quotes around the entire path
git rm "path/to/file with spaces.html"
Stuck in Command Prompt¶
Problem: Terminal not responding after a command
Solution: Press Ctrl + C to cancel the current operation
Vim Editor Confusion¶
Problem: Stuck in vim merge message editor
Solution:
1. Press Esc
2. Type :wq
3. Press Enter
Authentication Failures¶
Problem: Can't push/pull from GitLab
Solution: Use SSH authentication instead of HTTPS (covered in detail above)
Final Repository Structure¶
After all operations, the repository successfully synced: - Local changes pushed to GitLab - Remote GitLab files merged locally - Unnecessary files removed - SSH authentication configured for future operations
Best Practices Learned¶
- Always use
.gitignorefor system files like.DS_Store - SSH is better than HTTPS for regular Git work
- Use quotes around filenames with spaces or special characters
- Set upstream branch on first push with
-uflag - Pull before pushing when remote has changes
- Commit regularly with descriptive messages
Resources¶
- GitLab SSH Keys:
https://gitlab.fabcloud.org/-/user_settings/ssh_keys - Fab Academy GitLab:
https://gitlab.fabcloud.org - Git Documentation:
https://git-scm.com/doc
Documentation created: February 4, 2026 For: Fab Academy 2026 - Dorian Fritze