Git & Git Hub Flashcards
What is a version control system?
A system that tracks the differences between versions of files, typically used in software development.
What popular method is used to track software versions?
Version control technologies like Git and GitHub.
What is Git?
Git is a version control system designed to help users keep track of changes to files within their projects.
Who designed Git and why?
Linus Torvalds designed Git to manage changes to the Linux kernel, which has thousands of contributors.
What are some benefits of Git over other version control systems?
Git offers better speed, performance, reliability, free and open-source access, and an accessible syntax.
What is GitHub?
GitHub is a Cloud-based hosting service that lets you manage Git repositories from a user interface.
What is a Git repository?
A Git repository is used to track all changes to files in a specific folder and keep a history of those changes.
What additional features does GitHub provide beyond Git?
GitHub provides features like access control, pull requests, automation, documentation, ticketing, and project management.
How is GitHub like a social network?
GitHub users have profiles, can follow other users, and contribute to public projects from anywhere in the world.
What do you do after choosing the owner of the repository?
Input a repository name.
What file is often initialized with a new repository?
A README.md file.
What is a README.md file?
A markdown file used for documentation, which is shorthand for creating HTML pages.
What is the main branch in a Git repository?
The main branch is the default branch of the repository, also known as the main line.
What does the ‘Go to file’ button do in GitHub?
It allows users to view and access the files in the repository.
What command is used to clone a repository using HTTPS?
git clone followed by the HTTPS URL.
What command is used to list directories and hidden files in the terminal?
ls -la.
What is the .git directory?
A hidden folder that contains Git-related information for source control.
What is GitHub?
A cloud-based hosting service that lets you manage Git repositories from a user interface.
What command is used to navigate into a directory in the terminal?
cd followed by the directory name.
What does the command ‘ls -la’ do?
It lists all files and folders, including hidden ones.
What is the .git folder?
A hidden folder used to track all changes in a Git repository.
What are the three states in the Git workflow?
The three states are modified, staged, and committed.
What does it mean when a file is in the modified state?
The file has been changed but is not yet tracked by Git.
What is the staged state in Git?
The file is added to the staging area, where changes are tracked before being committed.
What does it mean when a file is in the committed state?
The file has been saved and a snapshot of the current changes has been taken.
What is the purpose of committing a file in Git?
To save the file and create a snapshot of the current changes.
What does the Git workflow involve?
A file is added from the working directory to the staging area, committed, and pushed to the remote repository.
What can be done after pushing a file to a remote repository?
The file can be fetched, checked out, or merged to a working directory.
What does the pwd command do?
It prints the working directory, showing the current directory location.
What does the git status command show?
It displays the current branch, the status of the working directory, and any changes to commit.
What is the purpose of the git add command?
To track new or modified files, adding them to the staging area for the next commit.
What does the touch command do?
It creates a new empty file, like test.txt.
What happens after running git add on a file?
The file moves to the staged state, ready to be committed.
What is the git restore command used for?
It can be used to unstage changes or restore files to their previous state.
What does the clear command do in the terminal?
It clears the terminal screen, making it easier to read.
What does the git commit -m command do?
It commits the staged changes with a message attached, describing the changes.
What is the purpose of the git push command?
To upload the local commits to the remote repository on GitHub.
What does the message ‘nothing to commit, working tree clean’ mean?
It means there are no changes to commit, and the working directory matches the repository.
What command is used to create a new branch and switch to it in Git?
git checkout -b followed by the branch name.
What is the difference between git branch and git checkout -b?
git branch creates a new branch, while git checkout -b creates a new branch and switches to it.
What is the purpose of a pull request?
To request a review and approval of changes made in a branch before merging into the main branch.
How do you push changes from a new branch to the remote repository?
Use git push -u origin followed by the branch name.
What is the difference between the main branch and a feature branch?
The main branch does not have knowledge of changes in a feature branch until the feature branch is merged back.
What does the git pull command do?
It pulls the latest changes from the remote repository to the local machine.
How can you merge a branch into the main branch?
Create a pull request on GitHub, review it, and then merge the branch into the main branch.
What happens after a pull request is approved?
The changes from the feature branch are merged into the main branch.
What command is used to check out the main branch in Git?
git checkout main.
What command is used to delete a branch after merging it?
You can delete the branch from GitHub after merging, or use git branch -d followed by the branch name.
What does the git push command do?
It uploads your local commits to the remote repository, syncing your local branch with the remote branch.
Why is it important to run git pull before git push?
To retrieve the latest changes from the remote repository, reducing the chances of a merge conflict.
What happens if your local branch is ahead of the remote branch?
Your local branch has changes that are not yet on the remote repository, which can be pushed using git push.
What does the git pull command do?
It retrieves changes from the remote repository and merges them into your local branch.
What is an auto merge in Git?
An automatic merge occurs when there are no conflicts between local and remote changes during a git pull or push.
How does Git handle conflicts during git push?
Git will fail the push if there are conflicts between local and remote files, requiring a manual resolution.
How can you check the contents of a file before and after git pull?
You can use the cat command to display the file contents.
What information does git status provide?
It shows the current branch, whether there are uncommitted changes, and whether the branch is ahead or behind the remote branch.
What is a workflow in programming?
A series of steps or processes that guide developers through tasks, ensuring smooth collaboration and deployment.
What is feature branching?
Feature branching is a workflow where a new branch is created from the main line to work on a feature, and then merged back into the main branch after completion.
Why is it important to keep the main branch clean in feature branching?
The main branch serves as the source of truth for the project, and changes are made in feature branches to prevent disruptions in the main branch.
What is the purpose of a pull request in feature branching?
A pull request allows developers to review and approve changes made in a feature branch before merging them into the main branch.
What command should you run before creating a new branch to ensure you have the latest code?
git pull.
How do you create a new branch in Git?
Use the git checkout -b command followed by the branch name.
What command is used to add new files to the staging area in Git?
git add followed by the file name or git add . to add all files.
What is the purpose of the -m flag in git commit?
It allows you to include a message describing the changes being committed.
What is the difference between committing and pushing in Git?
Committing adds changes to the local branch, while pushing sends those changes to the remote repository for others to see.
What is the purpose of the .git folder?
The .git folder tracks all changes across a project and contains information about branches, commits, and other version control data.
What is the HEAD file in Git?
The HEAD file is a pointer inside the .git folder that refers to the current commit or branch you’re working on.
How can you view the current branch in Git?
You can run the command cat .git/HEAD to see which branch the HEAD is pointing to.
What happens when you switch branches using git checkout?
When switching branches, the HEAD pointer is moved to the new branch, indicating that you are now working in that branch.
What command can be used to verify the current commit hash ID in Git?
Use the command cat .git/refs/heads/ to check the current commit’s hash ID for a branch.
How does the commit hash ID change after a commit?
Each commit generates a new hash ID that updates the current branch’s reference in the .git/refs/heads folder.
What is the function of the git add command?
git add stages changes to be committed in Git.
What does git commit -m do?
git commit -m commits staged changes with a message describing the changes.
How can you verify if the commit ID has changed after a commit?
Use the command cat .git/refs/heads/ to check if the commit hash ID has updated after the commit.
What is the purpose of the git diff command?
git diff is used to compare changes between files, branches, or commits, showing exactly what content was added or removed.
How do git status and git diff complement each other?
git status shows the names of the changed files, while git diff shows the specific changes made within those files.
What does a minus symbol represent in git diff output?
A minus symbol indicates content that has been removed compared to the previous version.
What does a plus symbol represent in git diff output?
A plus symbol indicates content that has been added compared to the previous version.
How can you compare a file against the HEAD using git diff?
Use the command git diff HEAD to compare the current state of a file against its last committed version.
How can you use git diff to compare two specific commits?
Use git log to get the commit IDs, then run git diff to compare changes between the two commits.
How do you compare changes between branches using git diff?
Use git diff to compare the differences between two branches.
What is the purpose of the pretty flag in git log?
The pretty flag is used to display the commit history in a more readable format.
What is the purpose of the git blame command?
git blame shows the changes made to a specific file, including the author, date, and time for each line of the file.
What information does git blame provide for each line of a file?
git blame provides the commit ID, author, timestamp, line number, and the actual change for each line.
How do you run the git blame command on a file?
Type git blame followed by the file name (e.g., git blame feature.js).
What does the commit ID represent in git blame?
The commit ID is a reference to the specific commit where the change occurred.
How can you limit git blame output to specific lines in a file?
Use the -L flag with git blame, followed by the starting and ending line numbers (e.g., git blame -L 5,15 ).
How can you view the actual changes of a specific commit from git blame?
You can copy the commit ID from git blame and use it with the git log -p command to see the detailed changes.
What does the -l flag do in git blame?
The -l flag in git blame allows you to format the output, such as showing full commit IDs or changing the date format.
What is the difference between git blame and git log?
git blame shows who made changes to each line of a file, while git log shows the detailed history of changes in commits.
What is the first step to fork a repository on GitHub?
Click the ‘Fork’ button on the GitHub repository page.
What happens after you click the ‘Fork’ button on GitHub?
You select the account where the repository will be forked.
What is the purpose of forking a repository?
Forking creates a copy of a repository in your own GitHub account to work on independently from the original project.
What is the command to create a new branch after forking a repository?
git checkout -b .
How do you commit changes after making edits to a forked repository?
Use git commit -m followed by a message to commit your changes.
How do you push changes from your local forked repository to the remote GitHub repository?
Use git push -u origin to push changes to the remote repository.
What is the next step after pushing changes to the remote repository in GitHub?
Create a pull request to merge the changes back into the original repository.
What does a pull request allow the original repository owner to do?
It allows the repository owner to review the changes and decide whether to accept or decline them.