Git Flashcards

1
Q

What is the git command that downloads any repository from GitHub to your computer?

A

The git command that downloads any repository from GitHub to your computer is

git clone <repository URL>

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

What are the 5 steps to push a file from your local system to the GitHub repository using Git?

A

Initialize Git: git init
Add file to staging area: git add <file>
Commit changes: git commit -m "Commit message"
Add remote repository: git remote add origin <remote repository URL>
Push changes: git push origin master

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

What is the process for reverting a commit that has already been pushed and made public?

There are two ways that you can revert a commit. What is the first?

A
  1. Remove or fix the bad file in a new commit and push it to the remote repository. Then commit it to the remote repository using:

git commit –m "commit message"

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

What is the process for reverting a commit that has already been pushed and made public?

There are two ways that you can revert a commit. What is the second?

A
  1. Use git log to find the commit hash of the specific commit you want to revert.
  2. Create a new commit that undoes all the changes that were made in the bad commit with this command:

git revert <commit id> Example: git revert 56de0938f

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

Explain the difference between Git Fetch and Git Pull.

A

Git Fetch: Fetches the latest changes from a remote repository to your local repository, but does not merge or modify your local branches.

Git Pull: Fetches the latest changes from a remote repository and automatically merges them into your current branch.

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

What is branching in Git?

A

Branching allows developers to work on new features, bug fixes, or experiments without affecting the main codebase until they are ready to be merged.

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

Pros of branching in Git? 3

A

Parallel Development
Collaboration and Code Review
Rollback and Versioning

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

Q: How do you create a new branch?

A

A: Use the command git branch branch_name to create a new branch with the given name.

After creating the branch, you can switch to it using the git checkout command: git checkout <branch-name>

Alternatively, you can combine the branch creation and checkout into a single command using the -b flag: git checkout -b <branch-name>

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

Q: How do you switch to a different branch?

A

A: Use the command “git checkout branch_name” to switch to the specified branch.

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

Q: How do you switch to a different branch?

A

A: Use the command “git checkout branch_name” to switch to the specified branch.

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

Is Git Merge or Git Rebase better?

A

It depends on the situation and project requirements.

If preserving the commit history and the order of commits is important, git merge is a better choice.

If you want a cleaner and more linear commit history without unnecessary merge commits, git rebase is preferred.

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

What scenarios usually require you to use git merge over git rebase and vice versa?

A

git merge is generally recommended for shared branches and collaborative projects,

git rebase is useful for individual feature branches

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

What are the advantages of Git Merge?

A

Git Merge preserves the original commit history and allows for easy identification of individual contributions.

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

What are the advantages of Git Rebase?

A

Git Rebase creates a clean and linear commit history without the additional merge commits, making it easier to follow changes.

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

What are the disadvantages of Git Rebase? 2

A

Rewrites commit history making it challenging for others to synchronize their work.

Risk of losing changes: Accidental loss or overwriting of commits if not performed correctly.

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

How do you find a list of files that have been changed in a particular commit?

A

The command to get a list of files that have been changed in a particular commit is:
git diff-tree –r {commit hash}

17
Q

How can a merge get resolved in Git?

A

It requires manual resolution by identifying conflicting lines, making necessary changes, and committing the resolved files.