3.0 Version Control with Git Flashcards

(103 cards)

1
Q

3.0 Version Control with Git

What is version control?

A

Practice of tracking and managing code changes

It enables multiple people to simultaneously work on a single project

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

3.0 Version Control with Git

What is another name for version control?

A

source control

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

3.0 Version Control with Git

How does version control help the development process?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

3.0 Version Control with Git

What are some basic concepts of version control?

A
  • Every code change and file is tracked
  • Keeps a history of changes
  • You can revert commits
  • Each change is labelled with a commit message
  • Git is the most used version control system
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

3.0 Version Control with Git

What is the difference between remote and local Git repos?

A
  • Remote repo is where the code is hosted on the internet (GitLab/GitHub)
  • Local repo is a local copy of the code on your machine

Code is fetched (“pulled”) from remote repo and “pushed” to it

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

3.0 Version Control with Git

What is a Git client?

A

UI or CLI that allows a user to interact with git

interact = connect and execute git commands

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

3.0 Version Control with Git

What is a merge conflict?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

3.0 Version Control with Git

How is a merge conflict resolved?

A

It is resolved manually through conversation between the developers to decide how the code should be written.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

3.0 Version Control with Git

How can merge conflicts be avoided?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

3.0 Version Control with Git

What are the different areas in git that code passes through?

A
  • Working directory
  • Staging area
  • Local repository
  • Remote repository
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

3.0 Version Control with Git

Explain git add file

A
  • Include the changes of a file into the next commit
  • Moves the changes from “working directory” to the “staging area”
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

3.0 Version Control with Git

Explain git commit -m "commit message"

A
  • Moves changes from staging area to your local repository
  • Creates a new commit, which you can go back to later if needed
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

3.0 Version Control with Git

Explain git push remote-url branch-name

A
  • After committing your changes to your local repo, you want to send your changes to the remote Git server
  • Uploads your commits to the remote repo
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

3.0 Version Control with Git

How do you authenticate your git client with GitHub/GitLab/etc?

A

Create an SSH key pair and add it to the remote platform.

GitLab: User Settings > SSH Keys > follow instructions

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

3.0 Version Control with Git

What are two Git global config commands to set up username and email?

A

git config –global user.name “Your Name”
git config –global user.email “your@email.com”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

3.0 Version Control with Git

How do you clone a repo and add a README.md file?

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

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?

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

3.0 Version Control with Git

What does it mean when Git says “fatal: not a git repository”?

A

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
~~~

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

3.0 Version Control with Git

Why does git remote add origin ... fail with “remote origin already exists”?

A

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>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

3.0 Version Control with Git

Why do I get “failed to push some refs” on first push?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

3.0 Version Control with Git

Pushing fails with “src refspec main does not match any” — why?

A

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
~~~

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

3.0 Version Control with Git

Why do I get authentication errors pushing over HTTPS?

A

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
~~~

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

3.0 Version Control with Git

Why do I get “Permission denied (publickey)” when using SSH?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Q

3.0 Version Control with Git

Pushing shows “repository not found” — why?

A

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>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
# 3.0 Version Control with Git Push fails with “**updates were rejected because the remote contains work that you do not have locally**.” Why?
Someone already pushed to the remote. Fix: pull first and merge: ```bash git pull origin main ``` or rebase: ```bash git pull --rebase origin main ```
26
# 3.0 Version Control with Git Why is nothing being committed (“**nothing to commit, working tree clean**”)?
All files are already committed or ignored by `.gitignore`. Run to check ignored files: ```bash git status --ignored ```
27
# 3.0 Version Control with Git Why does `git add .` do nothing for certain files?
`.gitignore` excludes them. Check which pattern is blocking the file: ```bash git check-ignore -v ```
28
# 3.0 Version Control with Git What if I accidentally initialized Git in the wrong directory?
Remove the `.git` folder: ```bash rm -rf .git ``` Then re-run `git init` in the correct place.
29
# 3.0 Version Control with Git How do I verify that my push actually updated the remote?
Check the remote branch: ```bash git log origin/main --oneline ``` Or use: ```bash git ls-remote --heads origin ```
30
# 3.0 Version Control with Git What is the purpose of **branches** in Git?
Branches allow better collaboration by letting developers work independently without breaking the main branch. ## Footnote This facilitates parallel development and reduces conflicts.
31
# 3.0 Version Control with Git What branch is created by default when a new repository is initialized?
The **main** branch (also historically called **master**). ## Footnote This is the primary branch where the stable code resides.
32
# 3.0 Version Control with Git Why do developers create **temporary branches**?
To work on features or bugfixes safely without risking stability of the main branch. ## Footnote This allows for isolated development.
33
# 3.0 Version Control with Git What is the best practice for using branches when developing features or fixing issues?
Create **one branch per feature or bugfix**. ## Footnote This simplifies tracking and merging changes.
34
# 3.0 Version Control with Git Give common **branch name patterns**.
* `main` * `dev` * `feature/...` * `bugfix/...` ## Footnote These patterns help in identifying the purpose of branches.
35
# 3.0 Version Control with Git Give an example of a **bugfix branch name**.
`bugfix/ticket-2134` ## Footnote This naming convention links the branch to a specific issue or ticket.
36
# 3.0 Version Control with Git Where do new branches typically **start from**?
From the **main branch**, using the same initial code base. ## Footnote This ensures consistency in development.
37
# 3.0 Version Control with Git What happens when a feature or bugfix branch is **complete**?
It is **merged back into the main branch**. ## Footnote This integrates the new changes into the stable codebase.
38
# 3.0 Version Control with Git What is the goal of keeping the **main branch stable**?
Ensuring the main branch is always ready for **production deployment**. ## Footnote Stability is crucial for reliable software delivery.
39
# 3.0 Version Control with Git What is a **merge request** (or pull request)?
A request to merge one branch into another, typically into the main branch. ## Footnote This facilitates code review and collaboration.
40
# 3.0 Version Control with Git Why do teams use **merge requests**?
To review code, collaborate, and ensure quality before merging. ## Footnote This process helps catch issues early.
41
# 3.0 Version Control with Git What can a reviewer do in a **merge request**?
View the changes and either approve or decline the merge. ## Footnote This is part of the quality assurance process.
42
# 3.0 Version Control with Git Why should a **DevOps engineer** know Git?
DevOps involves writing configuration files and scripts that need version control, collaboration, and secure storage. ## Footnote Understanding Git is essential for effective DevOps practices.
43
# 3.0 Version Control with Git Where should **IaC files** live?
In a **remote Git repository**, tracked and version-controlled. ## Footnote This ensures accessibility and collaboration.
44
# 3.0 Version Control with Git What does **CI** typically do on each merge?
Checkout code → test → build application. ## Footnote This process ensures that new changes do not break existing functionality.
45
# 3.0 Version Control with Git Which Git commands might a **CI/CD pipeline** need?
* Getting the commit hash * Checking if changes happened in certain directories (frontend/backend) ## Footnote These commands help in managing the build process.
46
# 3.0 Version Control with Git Why must **DevOps engineers** understand Git in CI/CD?
Because pipelines require integration with Git for checking out code, detecting changes, and automating builds/deployments. ## Footnote This knowledge is critical for effective CI/CD implementation.
47
# 3.0 Version Control with Git Initialize a new **Git repository** in the current directory
`git init` ## Footnote This command sets up a new Git repository in the specified directory.
48
# 3.0 Version Control with Git Clone a **remote repository**
`git clone ` ## Footnote This command creates a local copy of a remote repository.
49
# 3.0 Version Control with Git Stage all **changes**
`git add .` ## Footnote This command stages all modified and new files for the next commit.
50
# 3.0 Version Control with Git Commit staged **changes**
`git commit -m "message"` ## Footnote This command saves the staged changes to the repository with a message.
51
# 3.0 Version Control with Git Check **repository status**
`git status` ## Footnote This command displays the state of the working directory and staging area.
52
# 3.0 Version Control with Git List all **branches**
`git branch` ## Footnote This command shows all branches in the repository.
53
# 3.0 Version Control with Git Create a new **branch**
`git branch ` ## Footnote This command creates a new branch with the specified name.
54
# 3.0 Version Control with Git Switch to a **branch**
`git checkout ` ## Footnote This command changes the current working branch to the specified branch.
55
# 3.0 Version Control with Git Create and switch to a **branch**
`git checkout -b ` ## Footnote This command creates a new branch and switches to it in one step.
56
# 3.0 Version Control with Git Delete a **branch**
`git branch -d ` ## Footnote This command deletes the specified branch.
57
# 3.0 Version Control with Git Merge a **branch** into the current branch
`git merge ` ## Footnote This command integrates changes from the specified branch into the current branch.
58
# 3.0 Version Control with Git Start a **rebase**
`git rebase ` ## Footnote This command reapplies commits on top of another base tip.
59
# 3.0 Version Control with Git Abort a **rebase**
`git rebase --abort` ## Footnote This command stops the rebase process and returns to the original branch state.
60
# 3.0 Version Control with Git Continue a **rebase** after resolving conflicts
`git rebase --continue` ## Footnote This command continues the rebase process after conflicts have been resolved.
61
# 3.0 Version Control with Git Show **remote repositories**
`git remote -v` ## Footnote This command lists all remote repositories associated with the local repository.
62
# 3.0 Version Control with Git Add a **remote**
`git remote add origin ` ## Footnote This command adds a new remote repository with the specified URL.
63
# 3.0 Version Control with Git Change a **remote URL**
`git remote set-url origin ` ## Footnote This command updates the URL of an existing remote repository.
64
# 3.0 Version Control with Git Fetch changes from **remote**
`git fetch` ## Footnote This command retrieves updates from the remote repository without merging.
65
# 3.0 Version Control with Git Push current branch to **remote**
`git push` ## Footnote This command uploads the current branch's commits to the remote repository.
66
# 3.0 Version Control with Git Push and set upstream **tracking**
`git push -u origin ` ## Footnote This command pushes the branch to the remote and sets it to track the remote branch.
67
# 3.0 Version Control with Git Pull and **merge** changes
`git pull` ## Footnote This command fetches and merges changes from the remote repository into the current branch.
68
# 3.0 Version Control with Git Pull with **rebase**
`git pull --rebase` ## Footnote This command fetches changes and rebases the current branch on top of the upstream changes.
69
# 3.0 Version Control with Git Undo unstaged **changes** in a file
`git restore ` ## Footnote This command discards changes in the working directory for the specified file.
70
# 3.0 Version Control with Git Unstage a **file**
`git restore --staged ` ## Footnote This command removes the specified file from the staging area.
71
# 3.0 Version Control with Git Discard all unstaged **changes**
`git checkout -- .` ## Footnote This command reverts all unstaged changes in the working directory.
72
# 3.0 Version Control with Git Soft **reset** (keeps changes staged)
`git reset --soft ` ## Footnote This command resets the current branch to the specified commit while keeping changes staged.
73
# 3.0 Version Control with Git Mixed **reset** (default, unstages changes)
`git reset ` ## Footnote This command resets the current branch to the specified commit and unstages changes.
74
# 3.0 Version Control with Git Hard **reset** (discard ALL changes)
`git reset --hard ` ## Footnote This command resets the current branch to the specified commit and discards all changes.
75
# 3.0 Version Control with Git Modify the last **commit message**
`git commit --amend` ## Footnote This command allows you to change the message of the last commit.
76
# 3.0 Version Control with Git Interactive **rebase** to rewrite multiple commits
`git rebase -i ` ## Footnote This command opens an interactive interface to modify commit history.
77
# 3.0 Version Control with Git Force push **rewritten history**
`git push --force-with-lease` ## Footnote This command pushes changes to the remote repository, overwriting history if necessary.
78
# 3.0 Version Control with Git Show **commit history**
`git log` ## Footnote This command displays the commit history of the repository.
79
# 3.0 Version Control with Git Compact one-line **log**
`git log --oneline` ## Footnote This command shows a simplified view of the commit history.
80
# 3.0 Version Control with Git Graph view of **commits**
`git log --oneline --graph --all` ## Footnote This command visualizes the commit history in a graph format.
81
# 3.0 Version Control with Git Diff **unstaged changes**
`git diff` ## Footnote This command shows the differences between the working directory and the index.
82
# 3.0 Version Control with Git Diff **staged changes**
`git diff --cached` ## Footnote This command shows the differences between the index and the last commit.
83
# 3.0 Version Control with Git Diff between two **commits**
`git diff ` ## Footnote This command compares the changes between two specified commits.
84
# 3.0 Version Control with Git Set global **username**
`git config --global user.name ""` ## Footnote This command sets the username for all repositories on the system.
85
# 3.0 Version Control with Git Set global **email**
`git config --global user.email ""` ## Footnote This command sets the email address for all repositories on the system.
86
# 3.0 Version Control with Git View all **configuration**
`git config --list` ## Footnote This command displays all Git configuration settings.
87
# 3.0 Version Control with Git Stash current **changes**
`git stash` ## Footnote This command saves the current changes in a stack for later use.
88
# 3.0 Version Control with Git Apply latest **stash**
`git stash apply` ## Footnote This command reapplies the most recent stashed changes.
89
# 3.0 Version Control with Git Show list of **stashes**
`git stash list` ## Footnote This command displays all stashed changes.
90
# 3.0 Version Control with Git Create a **lightweight tag**
`git tag ` ## Footnote This command creates a tag at the current commit.
91
# 3.0 Version Control with Git Push **tags**
`git push --tags` ## Footnote This command pushes all tags to the remote repository.
92
# 3.0 Version Control with Git Why should **commit messages** be descriptive and meaningful?
Because clear commit messages make history understandable and help others follow changes easily. ## Footnote This practice enhances collaboration and project management.
93
# 3.0 Version Control with Git Why commit in **relatively small chunks**?
Smaller commits are easier to review, revert, and understand. ## Footnote This approach facilitates better tracking of changes.
94
# 3.0 Version Control with Git What is the rule about **grouping work** inside a commit?
Commit only *related* changes in a single commit. ## Footnote This ensures clarity and coherence in the commit history.
95
# 3.0 Version Control with Git What Git configuration should be set before committing?
Commit authorship information: * `user.name` * `user.email` ## Footnote This identifies the author of the commits.
96
# 3.0 Version Control with Git How do you keep your **feature or bugfix branch** up to date?
Pull regularly from the remote main/master or develop branch. ## Footnote This practice minimizes merge conflicts.
97
# 3.0 Version Control with Git Why shouldn't **branches stay open too long**?
Long-lived branches drift from main and cause merge conflicts; merging main often prevents this. ## Footnote Regular updates help maintain branch relevance.
98
# 3.0 Version Control with Git What is a good practice to avoid **deviations** between local and remote repositories?
Sync frequently by pulling from the remote. ## Footnote This keeps your local repository aligned with the remote.
99
# 3.0 Version Control with Git Why shouldn’t you **push straight to the main branch**?
It bypasses code review and risks breaking production. ## Footnote This practice ensures quality control.
100
# 3.0 Version Control with Git When is it appropriate to use **`--force` push**?
Only when working alone on a branch—**never** on main or develop. ## Footnote This prevents unintended overwrites in shared branches.
101
# 3.0 Version Control with Git What is the best practice for **naming branches**?
* `feature/` for features * `bugfix/` for fixes ## Footnote Consistent naming conventions improve clarity.
102
# 3.0 Version Control with Git Why use **merge requests (pull requests)**?
For code reviews, collaboration, and ensuring code quality before merging. ## Footnote This process enhances team communication.
103
# 3.0 Version Control with Git Why is a **`.gitignore` file** important?
It prevents committing unnecessary files like editor configs, build artifacts, or temporary folders. ## Footnote This keeps the repository clean and focused.