Things to remember GIT Flashcards

1
Q

How to create a new Git repository

A

git init

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

How to inspect the contents of the working directory and staging area?

A

git status / gst

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

How to add files from the working directory to the staging area?

A

git add

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

How to show the difference between the working directory and the staging area?

A

git diff

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

How to permanently store file changes from the staging area in the repository?

A

git commit -m “message”

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

How to show a list of all previous commits?

A

git log / git lg

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

How to discard changes in the working directory?

A

git checkout HEAD filename

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

How to unstages file changes in the staging area?

A

git reset HEAD filename

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

How to reset to a previous commit in your commit history?

A

git reset commit_SHA (7-first-digits of the commit)

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

How to add all files at once to the stage?

A

git add .

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

How to temporarly save/retrieve files in order to switch branches without loosing everything?

A

git stash

git stash pop

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

How to update your previous commit?

A

create your changes, stage them with git add and then type the command git
commit –amend

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

How to set up an alias for each command?

A

git config –global alias.co “checkout” (co becomes checkout)

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

How to move Files in the terminal?

A

mv file.txt destinared_directory

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

How to rename files in Terminal?

A

mv file.txt newFile.txt

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

Open VS Code from Terminal?

A

code .

17
Q

How to delete files from the terminal?

A

rm file.txt

18
Q

How do you create a local branch?

A

With git checkout -b new-branch-name.

myproject git:(master) git checkout -b new-branch-name
myproject git:(new-branch-name)
Be careful, always check the branch you currently are on before creating a new branch.

Most of the times you’ll want to be on master with the up-to-date version of master before starting a new feature.
To do so, git checkout master, git pull origin master and THEN create your new branch.

19
Q

How do you resolve a merge conflict with the command line?

A

On the laptop of the owner of the unmergeable branch:

git checkout master
git pull origin master
git checkout my-unmergeable-branch
git merge master
Then you solve conflicts locally (you can cmd + shift + f ‘»»»’ to find them quickly).

In your terminal:

git add .
git commit -m “conflict solving”
git push origin my-unmergeable-branch
Refresh your PR on GitHub, you can now merge your branch!

20
Q

How do you create a repo on GitHub?

A

gh repo create –public –source=.

21
Q

How do you print the list of local and remote branches in your terminal?

A

git branch -a

22
Q

How do you download an existing GitHub repo on your laptop?

A

mkdir ~/code/marcobaass
cd ~/code/marcobaass
git clone git@github.com:marcobaass/PROJECT_NAME.git
cd PROJECT_NAME

23
Q

How do you generate your User model using devise?

A

rails g devise User

24
Q

How to switch to a diffrent hard drive in bash?

A

cd /D (Capital Letter for the Drive)