Git Commands Flashcards

1
Q

git init

A

Initializes the folder as the project root and as a git repository

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

git add index.html

git add .

A

First adds index.html to the staging area

Second adds all files to the staging area

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

git add name*

A

adds files that start with ‘name’ to the staging area

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

git status

A

shows the repository status:

staged, unstaged, and untracked files

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

git commit

A

opens a text editor in the terminal to write a commit message

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

git commit -m “commit message”

A

writes the commit message without opening up an editor, everything in quotes is the message

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

git log

A

shows the commit history

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

git log -p

A

shows commit history including all files and their changes

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

git diff

git diff –staged

A

git diff shows all unstaged changes

adding –staged to see staged changes

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

git rm filename

A

will remove the file from the working tree and expect a commit message as to why

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

git mv oldName newName

A

renames files in git, expects a commit message

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

How do you ignore files in git?

A

create a .gitignore file and commit it

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

git reset HEAD filename

git reset HEAD -p

A

reverts staged changes in git

-p options flag to specify the desired changes to reset

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

git commit –amend

A

modifies the most recent commit

avoid if possible

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

git revert HEAD

A

reverts the latest commit

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

git revert commit_id

A

revert an older commit, opens up an editor for commit message

17
Q

git branch name

A

creates a new branch with the name provided

18
Q

git checkout branch

A

changes over to the declared branch

19
Q

git branch

A

lists all branches for the repository

20
Q

git checkout -b name

A

will create a branch and switch to it immediately

21
Q

git branch -d branch_name

A

will delete the declared branch

22
Q

git merge branch_name

A

merges the branch you are in with the branch declared

23
Q

git log –graph –oneline

A

shows the commit log as a graph, can use –all to show all branches

24
Q

git remove -v

A

shows all remote repositories at your local repository

25
Q

git add remote https://repo…

A

adds a remote repository to your local repository

26
Q

git push

A

pushes all changes to the remote repository

27
Q

git pull

A

retrieves the latest changes to the remote repository and performs a merge

28
Q

git fetch

A

downloads the changes from a remote repo, but will not perform a merge with your local repository

29
Q

git push -u origin branchName

A

pushes to a new ‘upstream’ branch

-u ‘upstream’

30
Q

git push -f

A

forces a push request, usually fine for pull request branches but should not be performed on public repos.

31
Q

git branch -M main

A

renames primary branch to main

32
Q

git clone https://remote.git

A

will clone a remote repository to the current directory