Git Flashcards

1
Q

How does Git work?

A

Git is a distributed version control system that works by:

Creating a local repository on a developer’s machine.
Tracking changes in files through snapshots (commits) of the project’s state.
Utilizing a staging area to organize changes before committing.
Allowing branching for parallel development lines.
Enabling collaboration through remote repositories.
Allowing users to push and pull changes between local and remote repositories.
Maintaining a complete history of commits for versioning and tracking changes.

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

What does Git’s internal architecture comprise?

A

Git’s internal architecture consists of:

Repository: Contains all project files and metadata, stored locally.
Objects: Git stores data as objects, including blobs (file contents), trees (directories), commits (snapshots), and tags (references to commits).
Index: Also known as the staging area, it stores changes to be committed.
References: Pointers such as branches, tags, and HEAD pointing to specific commits in the repository’s history.
Working Directory: The directory where files are checked out for editing.

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

What is a Git commit?

A

A Git commit represents a snapshot of the repository at a specific point in time. It includes changes made to files since the last commit, along with metadata such as author, timestamp, and a unique identifier (SHA-1 hash).

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

What is the purpose of the Git staging area (index)?

A

The staging area allows developers to organize and review changes before committing them to the repository. It acts as an intermediate step between modified files and the actual commit.

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

Explain the HEAD pointer in Git.

A

The HEAD pointer refers to the currently checked-out commit or branch in the repository. It points to the most recent commit on the current branch and represents the working directory’s state.

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

What are Git branches?

A

Git branches are independent lines of development within a repository. They allow developers to work on features or fixes separately, keeping changes isolated until they’re ready to merge.

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

How does Git handle merges?

A

Git merges changes from one branch into another by combining the commits from both branches. It automatically resolves simple merge conflicts and creates a new commit to record the merge.

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

What is a Git remote?

A

A Git remote is a reference to a repository hosted on a server (e.g., GitHub, GitLab). It enables collaboration by allowing users to fetch, pull, and push changes to and from that repository.

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

What is Git’s ‘git rebase’ command used for?

A

‘git rebase’ rewrites commit history by moving, combining, or modifying commits. It helps maintain a cleaner and linear history by incorporating changes from one branch onto another.

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

What is Git’s ‘git stash’ command used for?

A

The ‘git stash’ command temporarily stores changes that are not ready for commit. It allows developers to switch branches or perform other operations without committing unfinished work.

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

Explain Git’s ‘git blame’ command.

A

The ‘git blame’ command shows line-by-line details of who last modified each line in a file and the commit that introduced those changes. It helps identify the author and commit associated with specific changes.

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

What is the purpose of Git’s ‘git log’ command?

A

The ‘git log’ command displays the commit history in reverse chronological order. It shows information like commit hashes, authors, dates, commit messages, and the branching/merging history.

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

What is a local repository in Git?

A

A local repository in Git is the version control database stored on the developer’s machine. It contains the complete project history, branches, commits, and all tracked files.

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

What is the purpose of a local repository in Git?

A

The local repository allows developers to work on projects offline, commit changes, create branches, merge code, and perform version control operations without an internet connection.

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

What is a remote repository in Git?

A

A remote repository in Git is a copy of a project’s repository hosted on a remote server (like GitHub, GitLab, Bitbucket). It serves as a centralized location for collaboration and backup.

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

How do local and remote repositories interact in Git?

A

Developers clone a remote repository to create a local copy on their machine. They make changes in the local repository and can push those changes to the remote repository for collaboration and backup.

17
Q

What operations can be performed between local and remote repositories in Git?

A

Developers can push changes from the local repository to the remote repository, pull changes from the remote to the local, fetch updates from the remote, and manage branches and commits across both repositories.

18
Q

What are some drawbacks of using Git?

A

Learning Curve: Git has a steep learning curve for beginners due to its extensive feature set and command-line interface.
Complexity: Managing conflicts, branching strategies, and understanding advanced features can be complex.
Performance with Large Files: Git may have performance issues when handling very large files or repositories.
Centralization Dependencies: In centralized workflows, reliance on a single remote repository can pose a single point of failure.
Potential for Git Conflicts: Parallel development in branches may lead to conflicts that require manual resolution.
Reflog Dependency: Git’s reflog (a log of reference updates) might be a requirement for recovering lost commits or changes.

19
Q

What are some algorithms used in Git for version control?

A

SHA-1 Hashing: Git uses SHA-1 hashing to uniquely identify and track content within the repository. Each commit, file, and directory is assigned a unique SHA-1 hash based on its content.
Delta Compression: Git stores file changes as a series of snapshots. To optimize storage, it uses delta compression to store only the changes (deltas) between versions instead of entire files.
DAG (Directed Acyclic Graph): Git’s commit history forms a DAG structure, allowing branches, merges, and a clear history lineage of commits.
Packfile: Git uses packfiles to store objects efficiently by compressing multiple objects together, reducing storage overhead.
Merkle Trees: Used for efficient verification and integrity checking, Git employs Merkle trees to represent the content hierarchy, ensuring data consistency and quick verification.

20
Q

Delta Compression

A

Git employs delta compression to store file changes as a series of snapshots. It records only the changes (deltas) between versions instead of storing entire files, optimizing storage.

21
Q

DAG (Directed Acyclic Graph)

A

Git’s commit history forms a Directed Acyclic Graph (DAG) structure, allowing branches, merges, and a clear lineage of commits, ensuring a structured commit history.

22
Q

Packfile

A

Git uses packfiles to store objects efficiently by compressing multiple objects together. Packfiles reduce storage overhead by compressing objects into a single file.

23
Q

Merkle Trees

A

Merkle trees in Git represent the content hierarchy, enabling efficient verification and integrity checking. They provide a structure for quickly verifying data consistency.

24
Q

What does git init do?

A

git init is a Git command used to initialize a new Git repository in a directory. When executed, it sets up the necessary files and structures needed for version control, creating a .git directory that stores metadata and configuration for the repository.

25
Q

How does git init work ?

A

The git init command is what transforms a regular directory into a Git repository, allowing version control for the files within that directory. Here’s how it works:

Creates a .git directory: When you run git init in a directory, Git initializes the repository by creating a hidden directory named .git at the root of that directory. This directory contains all the necessary files and subdirectories to manage version control for the repository.

Sets up repository files and structure: Inside the .git directory, Git creates various subdirectories and files. Some of these include:

hooks: Contains scripts that trigger on specific Git events.
objects: Stores all the data for the committed files.
refs: Holds references to commits (branches, tags, etc.).
config: Configuration settings for the repository.
HEAD: Points to the currently checked-out branch.
Initializes the staging area and commit history: Git sets up an initial commit state, but no actual version history is created until you explicitly add files using git add and commit them using git commit.

Tracks changes: Once the repository is initialized, Git starts tracking changes in the directory and its subdirectories.

Enables version control: From this point on, you can use Git commands such as git add to stage changes, git commit to save those staged changes to the repository, and other Git functionalities for managing your project’s version history.

26
Q

What are Git hooks?

A

Git hooks are scripts that Git executes at specific points during version control actions like commit, merge, push, and receive. They allow customizing and automating workflows by triggering scripts in response to these events.

27
Q

Where are Git hooks located in a repository?

A

Git hooks are stored in the .git/hooks directory within a Git repository. Each hook is a script file with a specific name, and Git automatically executes these scripts when corresponding events occur.

28
Q

What are some common uses of Git hooks?

A

Git hooks can be used for various purposes such as pre-commit checks (linters, code formatting), enforcing commit message conventions, triggering automated tests before push, integrating with CI/CD pipelines, and more.

29
Q

What are Git refs?

A

Git refs, short for references, are pointers to specific commits within a Git repository. They include branch references, tag references, and the special HEAD pointer.

30
Q

Where are Git refs stored?

A

Git refs are stored in the .git/refs directory. Branches are typically stored in .git/refs/heads, tags in .git/refs/tags, and other special references in various locations within the .git/refs directory.

31
Q

How do Git refs function in Git’s version control system?

A

Git refs serve as labels or pointers to specific commit hashes. They allow users to easily navigate between different commits, branches, tags, and other references within a repository.