Git Flashcards
How does Git work?
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.
What does Git’s internal architecture comprise?
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.
What is a Git commit?
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).
What is the purpose of the Git staging area (index)?
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.
Explain the HEAD pointer in Git.
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.
What are Git branches?
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 does Git handle merges?
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.
What is a Git remote?
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.
What is Git’s ‘git rebase’ command used for?
‘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.
What is Git’s ‘git stash’ command used for?
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.
Explain Git’s ‘git blame’ command.
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.
What is the purpose of Git’s ‘git log’ command?
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.
What is a local repository in Git?
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.
What is the purpose of a local repository in Git?
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.
What is a remote repository in Git?
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.