Git commands Flashcards

You may prefer our related Brainscape-certified flashcards:
1
Q

Create a new repo with git -> set username

A

git config –global user.name “your name goes here”

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

Create a new repo with Git -> create a repo to work in

A

mkdir example
cd example
git init
(git init in existing folder is also possible I think)

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

see info about your Git repo

A

git status

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

add new file to Git repo

A

git add example.py

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

commit changes with message following the command,
what happens if not using a specific command for message?

A

git commit -m “creating example.py”
-m is to use the message that follows, otherwise git will bring up an editor to create the commit message

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

how to ignore files in your Git staging area?

A

with a .gitignore file

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

what files are usually added to a .gitignore file?

A

__pycache__
venv
env
.pytest_cache
.coverage

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

command to get to know more about gitignore

A

git help gitignore

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

command to see the history of the commits you made

A

git log command

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

command to change where we are in our history

A

git checkout THEHASHOFTHESHAYOUWANTTOGOTO
-> puts you in a ‘detached HEAD’ state
-> no branch is made

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

what is a HEAD?

A

the SHA you happen to be looking at, at any time.
It means what Git thinks you have checked out.

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

what does ‘detached HEAD’ state mean?

A

your HEAD is pointing to a SHA that does not have a branch (or label) associated with it

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

after changing to another SHA, how do you get back to where you were? (the last SHA committed to the master branch)

A

git checkout master

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

what does git checkout master do with the HEAD?

A

makes the head point to the SHA marked by the label, or branch, master

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

command to create a new branch

A

git checkout -b my_new_feature

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

command to compare the state of 2 branches

A

git show-branch my_new_feature master

17
Q

3 main ways to get commits from one branch to another

A

merging (simplest)
rebasing
cherry-picking

18
Q

what is merging?

A

Git creates a new commit that combines the top SHAs of 2 branches if it needs to.

19
Q

how to get commit from my_new_feature branch to master branch?

A

1) git checkout master
2) git merge my_new_feature

20
Q

explain cherry-picking + command

A

you specify exactly which commits you mean.

git cherry-pick HASHOFTHECOMMITYOUWANTTOADD

very handy when you want a specific change but not the entire branch that change was made on

21
Q

4 major Git commands that talk to remote repos

A

clone
fetch
pull
push

22
Q

How to make a local copy of a known repository when you have the address

A

example:

git clone git@github.com:jima80525/github-playground.git

go to the page of repository, click on “clone or download” and get the URI (= .git link) and clone it with the git command

23
Q

what does git fetch do

A

it updates all of the remotes/origin branches.
it will modify only the branches stored in remotes/origin and not any of your local branches