Git Commands Flashcards

Learn all the git commands

1
Q

Initialize a local Git repository

A

git init

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

Create a local copy of a remote repository

A

git clone

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

Check status

A

git status

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

Add a file to the staging area

A

git add [file-name.txt]

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

Add all changes to the staging area

A

git add -A

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

Add new files and modifications, without deletions to the staging area

A

git add .

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

Commit changes

A

git commit -m “I am message”

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

Remove a file or folder

A

git rm -r [file-name.txt]

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

List branches

A

git branch

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

List all branches (local and remote)

A

git branch -a

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

Create a new branch

A

git branch [branch name]

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

Delete a branch

A

git branch -d [branch name]

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

Delete a remote branch

A

git push origin –delete [branch name]

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

Create a new branch and switch to it

A

git checkout -b [branch name]

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

Clone a remote branch and switch to it

A

git checkout -b [branch name] origin/[branch name]

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

Switch to a branch

A

git checkout [branch name]

17
Q

Discard changes to a file

A

git checkout – [file-name.txt]

18
Q

Merge a branch into the active branch

A

git merge [branch name]

19
Q

Merge a branch into a target branch

A

git merge [source branch] [target branch]

20
Q

discard changes and store them in a dirty working directory

21
Q

Remove all discarded changes from the dirty working directory

A

git stash clear

22
Q

Push a branch to your remote repository

A

git push origin [branch name]

23
Q

Push changes to a remote repository (and remember the branDelete a remote branchch)

A

git push -u origin [branch name]

24
Q

Push changes to a remote repository (remembered branch)

25
Update local repository
git pull
26
Pull changes from a remote repository
git pull origin [branch name]
27
Add a remote repository
git remote add origin ssh://git@github.com/[username]/[repository-name].git
28
Set a repository's origin branch to SSH
git remote set-url origin ssh://git@github.com/[username]/[repository-name].git
29
View changes
git log
30
View detailed changes
git log --summary
31
Preview changes before merging
git diff [source branch] [target branch]
32
add all modifications and deletions, without new files to the staging area
git add -u
33
Discard all local changes to all files permanently:
git reset --hard