github Flashcards

1
Q

Version

A

git –version

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

Workflow

A
  1. git add .
  2. git commit -m [message]
  3. git push
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

check status of files

A

git status

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

Staging unstaged or untracked files

A

git add filename

git add dirname

git add .

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

committing staged files

A

git commit -m “message.”

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

What does SSH stand for?

A

Secure shell

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

checking for ssh file in project

A

in git bash:

ls -a -l ~/.ssh

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

checking for ssh file in project

A

in git bash:

ls -a -l ~/.ssh

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

How to generate an SSH key

A

in git bash, in the root directory:

ssh-keygen -t rsa -b 4096 -C “email address”

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

Concerning ssh keys, how can you get the ssh pid?

A

in git bash:

eval “$(ssh-agent -s)”

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

How to register ssh key or file?

A

in git bash:

ssh-add ~/.ssh/id_rsa

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

How to view current remote origins

A

git remote -v

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

How to remove a remote origin or destination

A

git remote rm origin

git remote rm destination

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

How to add a remote origin?

A

git remote add origin git@github.com:accountname/reponame

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

How to push repository to github?

A

git push -u origin master

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

How to acces the key of an .ssh file?

A

in git bash:

cat ~/.ssh/id_rsa.pub

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

How to test ssh connection?

A

in git bash:

ssh -T git@github.com

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

How to push to heroku?

A

git push heroku master

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

SSH key workflow

A
  1. check for existing key: ls -a -l ~/.ssh
  2. Generate a key: ssh-keygen -t rsa -b 4096 -C “email
    address”
  3. Check if keygen was succesful: eval “$(ssh-agent -s)”
  4. Register key: ssh-add ~/.ssh/id_rsa
  5. Access key in file: cat ~/.ssh/id_rsa.pub
  6. Setup SSH with provider
  7. Test connection: ssh -T git@github.com
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

General Git workflow

A
  1. git add .
  2. git commit -m “message.”
  3. git push origin master
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

How to clone a specific branch

A

git clone –single-branch –branch

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

Difference between git clone and git pull?

A

git clone is how you get a local copy of an existing repository to work on. It’s usually only used once for a given repository, unless you want to have multiple working copies of it around. (Or want to get a clean copy after messing up your local one…)

git pull (or git fetch + git merge) is how you update that local copy with new commits from the remote repository. If you are collaborating with others, it is a command that you will run frequently.

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

Difference between clone, pull, fork, and push

A

git clone means you are making a copy of the repository in your system.

git fork means you are copying the repository to your Github account.

git pull means you are fetching the last modified repository.

git push means you are returning the repository after modifying it.

In layman’s term:

git clone is downloading and git pull is refreshing.

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

How to see a list of git commits?

A

git log

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

How to clone a git repository into a manually named directory?

A

git clone [url] [dirName]

26
Q

How can we display only the commits of log messages?

A

git log –oneline

27
Q

git log flag that shows which files have changed

A

git log –stat

28
Q

Which log flag show exactly which changes have been made

A

git log -p or git log –patch

29
Q

How to see a specific commit

A

git log [SHA] -p

git show [SHA]

30
Q

Do’s and Don’ts for commit messages

A

Do

  • do keep the message short (less than 60-ish characters)
  • do explain what the commit does (not how or why!)

Do not

-do not explain why the changes are made (more on this below)
-do not explain how the changes are made (that’s what git log -p is for!)
-do not use the word “and”
if you have to use “and”, your commit message is probably doing too many changes - break the changes into separate commits
e.g. “make the background color pink and increase the size of the sidebar”

The best way that I’ve found to come up with a commit message is to finish this phrase, “This commit will…”. However, you finish that phrase, use that as your commit message.

Above all, be consistent in how you write your commit messages!

31
Q

Which command can be used to see changes that have been made but haven’t been committed, yet?

A

git diff

32
Q

How to display tags

A

git tag

33
Q

how to delete a tag

A

git tag -d [tag name]

git tag –delete [tag name]

34
Q

How to add a tag

A

git tag -a [tag name] (the stands for annotate)

35
Q

How to create a new branch

A

git branch [branchName]

36
Q

How to move the head pointer to a specific branch

A

git checkout [branchName]

37
Q

How do we delete a branch?

A

git branch -d [branchName]

38
Q

How to add a branch at a specific commit?

A

git branch [branchName] [SHA-abreviated]

39
Q

How to create a new branch and check it out at the same time?

A

by useing the -b flag

git checkout -b [branchName]

40
Q

How to see logs of all branches at the same time

A

git log –oneline –decorate –graph –all

41
Q

How to merger a branch with the master branch

A

git merge [branchName]

42
Q

How to undo a merge?

A

git reset –hard HEAD^

43
Q

How to ammend the most recent commit message

A

git commit –amend

44
Q

How to undo file changes that has been committed?

A

git revert [sha]

45
Q

Reset vs Revert

A

At first glance, resetting might seem coincidentally close to reverting, but they are actually quite different. Reverting creates a new commit that reverts or undos a previous commit. Resetting, on the other hand, erases commits!

46
Q

Relative Commit References

A

You already know that you can reference commits by their SHA, by tags, branches, and the special HEAD pointer. Sometimes that’s not enough, though. There will be times when you’ll want to reference a commit relative to another commit. For example, there will be times where you’ll want to tell Git about the commit that’s one before the current commit…or two before the current commit. There are special characters called “Ancestry References” that we can use to tell Git about these relative references. Those characters are:

^ – indicates the parent commit
~ – indicates the first parent commit
Here’s how we can refer to previous commits:

the parent commit – the following indicate the parent commit of the current commit
HEAD^
HEAD~
HEAD~1

the grandparent commit – the following indicate the grandparent commit of the current commit
HEAD^^
HEAD~2

the great-grandparent commit – the following indicate the great-grandparent commit of the current commit
HEAD^^^
HEAD~3

The main difference between the ^ and the ~ is when a commit is created from a merge. A merge commit has two parents. With a merge commit, the ^ reference is used to indicate the first parent of the commit while ^2 indicates the second parent. The first parent is the branch you were on when you ran git merge while the second parent is the branch that was merged in.

47
Q

How to delete a recent commit

A

git reset

git reset HEAD^

48
Q

Flags for git reset

A
  • -mixed (default) (moves commit to working directory)
  • -soft (moves commit to staging index)
  • -hard (moves commit directly to trash)
49
Q

How to make a backup of branch before attempting to reset it, and then restor the backup?

A

git branch backup

then when need to restor simple checkout the master and git merge backup

50
Q

How to pull remote repo down to local computer?

A

git pull origin master

51
Q

When would you use git fetch instead of git pull?

A

When you dont want to automatically merge the local branch with the tracking branch.

Git pull automatically does a forward merge with tracking branch

52
Q

What if there the remote is several commits ahead of the local repo and there are some commits in the local repo that has not yet been pushed up to the remote?

A

git fetch origin master

git merge origin/master

git push origin master

53
Q

what is git fork

A

git fork, makes a identical copy of a repo after which you become the owner of that copy

54
Q

How to see a short list of commits by individual contributers?

A

git shortlog

55
Q

Which flags can be added to git shortlog?

A

git shortlog displays an alphabetical list of names and the commit messages that go along with them. If we just want to see just the number of commits that each developer has made, we can add a couple of flags: -s to show just the number of commits (rather than each commit’s message) and -n to sort them numerically (rather than alphabetically by author name).

56
Q

how to filter logs by a particular author

A

git log –author=Surma

57
Q

How to find a commit that references a particular term?

A

git log –grep=[term]

58
Q

Workflow for contributing to other developers repos

A
  1. fork repo
  2. clone to working directory
  3. check-out new branch
  4. commit changes
  5. push to forked repo
59
Q

how to setup an upstream repo

A

git remote add upstream [url]

60
Q

How to rename remotes

A

git remote rename mine origin

61
Q

How to combine a number of commits into one larger commit?

A

git rebase

example:

git rebase -1 HEAD~3

NB: before squashing commits, you should first create a backup branch

62
Q

Rebase commands

A

use p or pick – to keep the commit as is
use r or reword – to keep the commit’s content but alter the commit message
use e or edit – to keep the commit’s content but stop before committing so that you can:
add new content or files
remove content or files
alter the content that was going to be committed
use s or squash – to combine this commit’s changes into the previous commit (the commit above it in the list)
use f or fixup – to combine this commit’s change into the previous one but drop the commit message
use x or exec – to run a shell command
use d or drop – to delete the commit