Git Flashcards

1
Q

What is version control?

A

Version control is a system that records changes to a file or set of files over time so that you can recall specific versions later.

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

What are the benefits of a version control system?

A

You can:

revert files back to a previous state.

Revert the entire project back to a previous state,

Review changes made over time:

See who last modified something that might be causing a problem.

Who introduced an issue and when.

if you screw things up or lose files, you can generally recover easily.

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

What is git?

A

git is a version control system.

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

When working in a git project and you have broken your code what can you do to fix it?

A

You can revert back to when it wasn’t broken.
you can look to see which parts of the project have been changed.

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

What is a git repo and what is it short for?

A

A repo or repository is just a collection of files, which most likely contain your code.

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

What are the four fundamental areas in the git workflow?

A

Working Directory
Staging Area
Local Repository
Remote Repository

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

Consider a file in your Working Directory that you have made changes to, what three possible states can it be in?

A

It can be modified.
It can be staged.
It can be committed.

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

What does it mean when a file is staged?

A

It mean the file is marked to be committed to the local repository but is not yet committed.

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

What does it mean when a file is modified?

A

It means the file has been modified but the changes are yet to be stored in the local repository.

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

What does it mean when a file is committed?

A

It means that the changes you made to your file are safely stored in the local repository.

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

What does the command “git add” do?

A

“git add” is a command used to add modified files to the staging area. Modified files includes new files, modified files or deleted files.

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

What does the command “git commit” do?

A

git commit is a command used to add all files that are staged to the local repository.

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

What does the command “git push” do?

A

“git push” is a command used to add all committed files in the local repository to the remote repository. So in the remote repository, all files and changes will be visible to anyone with access to the remote repository.

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

What does the command “git fetch” do?

A

git fetch is a command used to get files from the remote repository to the local repository but not into the working directory.

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

What does the command “git pull” do? What is it equivalent to?

A

git pull is command used to get files from the remote repository directly into the working directory. It is equivalent to a “git fetch” and a “git merge” .

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

What command tells you the version of git you have installed?

A

“git –version”

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

What are SSH keys used for with git?

A

With SSH keys, you can connect to GitHub without supplying your username or password at each visit.

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

What command lets you view more information about a git command?

A

git help command

e.g.
git help add

This will open an information page in a browser.

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

Which command adds all new, deleted and modified files in the working directory to the staging area?

A

git add -A

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

What command shows you the files in the staging area?

A

git status

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

What command do you use to commit files to your local repo?

A

git commit -m “commit message goes here”

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

What command do you use to add a new remote repo? This will be a remote repo you push your local repo up to.

A

git remote add origin remote_repository_URL

git remote add origin https://github.com/ThomasAlexanderMann/react_challenge.git

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

What command lists the URLs of the remote connections you have to other repositories

A

git remote -v

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

What command pushes the changes in your local repository up to the remote repository you specified as the origin.

A

git push

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

What command shows you the changes made to files that are not yet staged?

A

git diff

Once they are staged they do not show up with this command.

26
Q

What command lets you see the history of commits you have made to your files?

A

git log

27
Q

You have made changes to your working directory, what are the 4 commands you will typically use to apply these changes to the remote repo?

A

git add -A # Adds modified files to the staging area
git status # Lists all new or modified files to be committed
git commit -m “I’m committing some changes”
git push origin main

28
Q

What command do you use to clone a repo?

A

git clone remote_repository_URL

This will clone the repository into the current directory your terminal is in.

29
Q

What is a pull request?

A

A pull request is an action in GitHub to merge the changes in one branch into another following a review.

30
Q

What command creates a new local branch and moves you into it?

A

git checkout –b branch-name-separated-by-hyphens

This creates a new branch and also switches you to that branch.
Note that the new branch is only on the local repository until it gets pushed to the remote repository (AKA GitHub).

31
Q

What command can you use to switch branch?

A

git checkout name-of-branch

32
Q

What is the purpose of git stash in vs code?

A

If you have uncommitted changes in a branch switch to another branch the changes you made will be present in the new branch.
Use stashes to store the changes to come back to them later without having to commit them.

33
Q

How do you view your git username and email from the command line?

A

$ git config –global user.name
$ git config –global user.email

In VS code they may be blank/empty as signing in to VS code with your GitHub account skips the step where they are assigned values.

34
Q

Where can you see the changes you have made to files in VS code?

A

In the source control tab. Click the file to see the before and after comparison. Very useful especially before a commit.

35
Q

What command shows you your local branches?

A

git branch

36
Q

What command shows you your remote branches?

A

git branch -r

37
Q

What command shows you local and remote branches?

A

git branch -a

38
Q

When should I use git commit –amend

A

When i have created a new local commit and I want to alter the files in the commit or the commit message. Don’t amend other developers commits because git commit –amend will create a new commit and the original commit will no longer be on the current branch. It is difficult to recover the original commit.

39
Q

What command lets you add your username to git?

A

git config –global user.username ThomasMann

NOTE: this is a different variable to user.name

40
Q

What is a commits parent?

A

The commit that the current commit was based off.

41
Q

What are branches?

A

Branches are simply pointers to a specific commit – nothing more.

42
Q

Just remember that a branch essentially says what?

A

A branch essentially says “I want to include the work of this commit and all parent commits.”

43
Q

You create a new branch from main, does it point to the same commit as main? Why?

A

Yes, the new branch will refer to the same commit and all its parent commits. This because branches are simply pointers to a specific commit – nothing more.

44
Q

What type of commit does merging in Git create? What does this mean?

A

Merging in Git creates a special commit that has two unique parents. A commit with two parents essentially means “I want to include all the work from this parent over here and this one over here, and the set of all their parents.”

45
Q

You merge a branch into main and get a new commit, how many parents does this new commit have?

A

It has two parents the commit that main points to and the commit that the other branch points to.

46
Q

What is Rebasing?

A

Rebasing essentially takes a set of commits, “copies” them, and plops them down somewhere else.

47
Q

What is the advantage of rebasing?

A

The advantage of rebasing is that it can be used to make a nice linear sequence of commits.

48
Q

What is the HEAD?

A

HEAD is the symbolic name for the currently checked out commit – it’s essentially what commit you’re working on top of.

49
Q

What does detaching HEAD mean?

A

Detaching HEAD just means attaching it to a commit instead of a branch.

50
Q

What command would you use to checkout a specific commit and detach your HEAD?

A

git checkout

51
Q

In ‘detached HEAD’ state will any commits made remain when you switch branch?

A

In ‘detached HEAD’ state. You can look around, make experimental changes and commit them, and you can discard any commits you make in this state without impacting any branches by switching back to a branch.

52
Q

What command lets you view what the HEAD is currently pointing to?

A

git log

53
Q

Git is smart about hashes in what way for example:
git checkout fe5d2

A

The upside is that Git is smart about hashes. It only requires you to specify enough characters of the hash until it uniquely identifies the commit. So I can type fe5d2 instead of the full commit hash.

54
Q

What does the following command do?
git checkout main^

A

It checks out the 1st parent commit of the commit that main is pointing to.

55
Q

What does the following command do ?
git checkout HEAD^

A

It checks out the 1st parent commit of the commit that HEAD is pointing to. It allows you to move up the commit tree.

56
Q

What does the following command do?
git checkout HEAD~4

A

it checks out the 4th parent commit from the commit HEAD is pointing at. It goes back 4 commits in the commit history.

57
Q

What does the following command do?
git branch -f main HEAD~3

A

You can directly reassign a branch to a commit with the -f option. The command moves (by force) the main branch to three parents behind HEAD.

58
Q

There are two primary ways to undo changes in Git, what are they?

A

git reset and git revert.

59
Q

How does git reset reverse changes ?

A

git reset reverses changes by moving a branch reference backwards in time to an older commit. In this sense you can think of it as “rewriting history;” git reset will move a branch backwards as if the commit had never been made in the first place.

60
Q

How does git revert reverse changes?

A

It makes the changes on a new commit. This means no commit history is lost.