3.0 Version Control with Git
What is version control?
Practice of tracking and managing code changes
It enables multiple people to simultaneously work on a single project
3.0 Version Control with Git
What is another name for version control?
source control
3.0 Version Control with Git
How does version control help the development process?
Since code is hosted centrally on the internet, it enables multiple devs to simultaneously work on a single project.
Every developer has an entire copy of the code locally.
3.0 Version Control with Git
What are some basic concepts of version control?
3.0 Version Control with Git
What is the difference between remote and local Git repos?
Code is fetched (“pulled”) from remote repo and “pushed” to it
3.0 Version Control with Git
What is a Git client?
UI or CLI that allows a user to interact with git
interact = connect and execute git commands
3.0 Version Control with Git
What is a merge conflict?
It’s when Git tries to merge changes from multiple developers but the same line was changed and it doesn’t know how to handle it.
3.0 Version Control with Git
How is a merge conflict resolved?
It is resolved manually through conversation between the developers to decide how the code should be written.
3.0 Version Control with Git
How can merge conflicts be avoided?
Mainly Push and pull often from remote
repository to stay in sync
Also, it also helps if devs are aware of which part of the baseline each other is working on
Breaking changes doesn’t affect you until you pulled the new code.
3.0 Version Control with Git
What are the different areas in git that code passes through?
3.0 Version Control with Git
Explain git add file
3.0 Version Control with Git
Explain git commit -m "commit message"
3.0 Version Control with Git
Explain git push remote-url branch-name
3.0 Version Control with Git
How do you authenticate your git client with GitHub/GitLab/etc?
Create an SSH key pair and add it to the remote platform.
GitLab: User Settings > SSH Keys > follow instructions
3.0 Version Control with Git
What are two Git global config commands to set up username and email?
git config –global user.name “Your Name”
git config –global user.email “your@email.com”
3.0 Version Control with Git
How do you clone a repo and add a README.md file?
git clone git@gitlab.com:username/your-project.git
cd your-project
touch README.md
git add README.md
git commit -m “add README”
git push -u origin master
3.0 Version Control with Git
If you already have an existing project locally, how do you initialize a git repository and push it to your remote platform?
cd myproject
git init
git add .
git commit -m “Initial commit”
git remote add origin git@gitlab.com:group/project.git
git branch -M main
git push -u origin main
3.0 Version Control with Git
What does it mean when Git says “fatal: not a git repository”?
You’re running Git commands in a folder that hasn’t been initialized. Run:
```bash
git init
~~~
Or navigate to the correct directory:
```bash
cd /path/to/project
~~~
3.0 Version Control with Git
Why does git remote add origin ... fail with “remote origin already exists”?
A remote named origin is already configured. Fix with:
```bash
git remote set-url origin <URL>
~~~</URL>
or remove and re-add:
```bash
git remote remove origin
git remote add origin <URL>
~~~</URL>
3.0 Version Control with Git
Why do I get “failed to push some refs” on first push?
The remote isn’t empty — it already has commits (like a README). Fix by pulling with unrelated histories allowed:
```bash
git pull origin main –allow-unrelated-histories
~~~
Resolve conflicts → commit → push again.
3.0 Version Control with Git
Pushing fails with “src refspec main does not match any” — why?
You don’t have a branch named main yet, usually because nothing was committed. Fix:
```bash
git add .
git commit -m “Initial commit”
git branch -M main
git push -u origin main
~~~
3.0 Version Control with Git
Why do I get authentication errors pushing over HTTPS?
GitHub/GitLab require Personal Access Tokens, not passwords. Fix: update the remote to use SSH or generate a PAT.
SSH example:
```bash
git remote set-url origin git@gitlab.com:group/project.git
~~~
3.0 Version Control with Git
Why do I get “Permission denied (publickey)” when using SSH?
SSH key not loaded or not added to GitLab/GitHub. Fix:
```bash
ssh-keygen -t ed25519
ssh-add ~/.ssh/id_ed25519
~~~
Then add id_ed25519.pub to the platform.
3.0 Version Control with Git
Pushing shows “repository not found” — why?
Usually:
* Wrong remote URL
* No access rights
* Repo deleted or private
Verify:
```bash
git remote -v
~~~
Correct with:
```bash
git remote set-url origin <correct-url>
~~~</correct-url>