Git Flashcards

1
Q

What is SCM?

A

Source Control Management; also as Version Control System, VCS

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

Why is Github a DVCS?

A

It is a Distributed Version Control System because it does not have a main central repo.

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

How to create a git repo in your local directory?

A

$ git init

  • This command creates a hidden directory called .git in your current directory
    • Note not to create nested git repo, delete the .git dir. if it is already under a dir. with .git
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What does .gitignore do?

A

When you create the .gitignore file under your local git repo, Github will not allow any files you specify in .gitignore to be uploaded.

**always create .gitignore when you initiate a repo

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

What does $ git status do?

A

It tells about our working tree & staging area:

1) Which branch and branch name you’re on
2) If there are files that are untracked (and advise to “$ git add” file)
3) Changes to be committed (Staged files that are waiting to be committed)

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

What is a “commit” in Git?

A

A commit is a bundle of changes:

Addition of new files / deletion of existing files/ moving pushing pulling merging commits around.

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

How to stage files in your git repo? LOCALLY

What does staging a file mean?

A

$ git add FILE.txt FILE2.md

Staging is like a warehouse that your file is ready to be committed but also available to be changed. If you change the files, you need to stage them again.

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

How to commit a file in Git? LOCALLY

A

$ git commit -m ‘Add first project files’

The flag “-m” is about attaching a message to the commit. It is like a explaining tag for that particular changes.

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

How do you check your history of commits?

A

$ git log

** Having a good commit hygiene is important at work. One commit should represent one thing, e.g. a bug fixed, a feature added, etc.

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

What is branching? What is your default branch?

A

The default branch name is “master”.

We create a new branch - or fork it from an existing branch. The new branch contains the past history of the old branch and from that point on, the log history of two branches will be different.

If the new branch of codes fail, you delete it; if it works, you merge back to the master branch.

**Only commits are forked and merged but not the staged files

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

How do you link your local repo to remote repo on Github?

A

$ git remote add origin https://github.com//repo_name.git

git remote => command to work with remote repo

add => link the local repo to remote repo // you can also execute remove/ modify

origin => alias for Github remote repo; it’s a convention to name its ‘origin’ on Github. You can name it whatever you like in this command but origin usually means the central remote repo.

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

How to push commits to Github remote repo?

A

$ git push -u origin master

git push => primary command to push commits to remote repo

-u => set upstream tracking branch // link local master branch to remote master branch (from now on, you’ve tracked local branch to a specific remote branch)

origin => alias of remote repo

master => remote repo branch

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

How to pull commits from Github remote repo?

A

1) Fetch the changed repo to our local repo
$ git fetch (need to specify branch if not specified previously)

2) Check the difference between the downloads and local repo.

$ git diff master origin/master
=> the first master is your local master branch ; the second one is the master branch in remote origin repo.

3) Pull the repo into your local repo finally
$ git pull (if branch not tracked, $ git pull origin master)

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

What does $ git diff do?

A

It provides to compare the first repo and second repo you specify in later arguments.

=> $ git diff master origin/master

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