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 clone an existing GitHub repo on your computer?

A

fork the repo on github.com

under code copy the SSH adress

git clone ‘ssh-adrress.git’

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)

25
Q

How to delete a project and it’s files in the terminal?

A

rm -rf my-project

26
Q

How to merge a branch into main?

A
git merge branch-name
27
Q

How to delete a branch?

A
git branch -d branch-name
28
Q

How to list all branches?

A
git branch
29
Q

How to create a new branch?

A
git branch branch-name
30
Q

How to switch from one branch to another?

A
git checkout branch_name
31
Q

How to merge origin/master into your local
branch?

A
git merge origin/master
32
Q

A common Git collaboration workflow is?

A
  1. Fetch and merge changes from the remote
  2. Create a branch to work on a new project feature
  3. Develop the feature on a branch and commit the work
  4. Fetch and merge from the remote again (in case new commits were made)
  5. Push branch up to the remote for review

Steps 1 and 4 are a safeguard against merge conflicts, which occur when two branches contain file changes that cannot be merged with the git merge command.