Git Flashcards

1
Q

What am I going to learn?

A

Everything I need to know to use Git like a pro

Work effectively with others

Fundamental concepts

Creating snapshots of code

browsing project history

collaborating using Github

rewriting history

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

What is Git and why is it popular?

Hint: track history, work together

A

most popular version control system in the world

More than 90% of software projects globally use Git

Almost every job description for software developer mentions Git

records changes made to code over time in a repository

can look at project history to see who made which changes when

can revert project back to earlier state

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

What is a centralized version control system?

A

All team members connect to central server to get latest code + share code

Problems?

Single point of failure

if server goes down, cannot collaborate

must wait for server to go back up to work together and save snapshots of code

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

What is a de-centralized version control system?

A

every team member has a copy of the project with it’s history on their machine

we can save snapshots of the project locally, on our machine

if server is offline, can synchronize directly with others

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

What must be in your toolbox if you want to get hired as a software developer?

A

Know the in’s and out’s of Git

How it works

How to track project history

How to work together effectively

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

How can we use Git?

A

Command line

fastest way, many people use

this course will focus on command line

Code Editors and IDEs

built in support for Git features w/ plugins for special features (GitLens, VS code, etc.)

Graphical user interfaces

tools for windows, mac, windows, Linux

GitKraken (GUI for Git) integrates with GitKraken boards (error tracking), timelines (project roadmaps)

have limitations, not always available

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

What are the different levels we can config Git?

A

System - all users

Global - all repos of the current user

Local - current repo

We can have different settings for different projects or repositories

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

What settings do we need to specify?

A

Name, Email, Default Editor

Line Ending (auto.crlf)

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

Why do we have to handle “end of line” settings properly?

A

Windows and Mac have different end of line characters

If we don’t setup line ending properly, will end up with issues down the road

Solution?

Configure variable corecrlf (carriage return line feed)

Windows Users (Git)

remove carriage return line characters (check into repo)

add carriage return line characters (check out repo)

Mac Users

don’t add carriage return characters

remove carraige return line characters if present before (check into repo)

Input - only modify end of lines, when storing into repository

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

How do we create a new repository?

A

Commands

$mkdir RepoName

$cd RepoName

$git init

Under the Hood

(implementation detail)

creates a .git file w/in directory (hidden)

.git file stores info about our project

project history, branches, hooks, objects, info, references

purely implementation details

don’t corrupt this file (will lose project history)

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

What is the git workflow?

A

Working Directory (Project Directory)

local to my machine

Index (Staging area)

.add command

intermediate step

review code before commit

Git Repository

subdirectory (hidden) in working directory

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

What does each commit contain?

Hint: complete snapshot

A

each commit contains…

a unique identifier

generated by git

information about change

Message

Date/Time

Author

complete snapshot of project (not only changes)

can revert to earlier version quickly without computing changes

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

What is the echo command?

A

A standard Unix / Linux command for writing content to a file

echo hello > file1.txt

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

What does $git status show us?

A

see status of working directory or staging area

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

How do we add files to staging area?

A

git add * .txt

all files with .txt ending

git add file1.txt file2.txt

multiple files separated by space

git add .

adds all files in current directory

beware some files we don’t want to add (.gitignore)

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

If we stage a file, then make a change locally, what must we do?

A

$git add fileName.ext

add to staging area again

Why?

Git stores a snapshot of file when $git add . to staging area

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

How do we store our snapshot permanently in our git repository?

A

$git commit -m “meaningful snapshot description”

bug constraints explained

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

What are best practice guidlines for commits?

A

whole point of commits is to record checkpoints

if a mistake is made, can go back to last checkpoint

each commit represents a single unit of work

DO LIST

commit often (5-10 times per day, depending on work)

commit at each checkpoint

As I reach a state I want to record, THEN make a commit

each commit should represent a logically chained step

give each commit message a meaningful comment (messages show in history)

Use present tense in commit message

DO NOT DO

make a commit everytime a file is updated

wait three days, then make a commit

build a feature end to end before making a commit

Do not wait until BIG commit to make a commit

commit two logical steps together

Ex. don’t commit bug fix / typo fix together (separate these)

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

How do we skip staging?

A

99% of time, stage code before commiting

Beware (only due if sure, don’t need to review)

-a all

-m message

$git commit -am

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

How do we remove a file from working directory?

Hint: remove from working directory,

.add + commit to remove from staging directory

A

$rm file2.txt

linux cmmd removes from working directory

still in staging directory (ls)

Soln?

Must stage changes using add command

$git add file2.txt

stages deletion

$git commit -m

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

How do we remove a file from working directory and staging files?

A

$git rm file2.txt

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

How do we move or rename files?

Hint: $git mv newFileName oldFileName

A

$ mv file1.txt main.js

rename file1.txt to main.js

Two step process:

  1. Modify working directory
  2. Stages two changes (add / delete)

$git mv

does this for us vs. standard unix command

changes are applied to both working directory and staging directory

$git commit -m

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

How do we ignore files?

A

certain files we want to ignore:

log files: individual for each developer, don’t want to include

node_modules: increase size of code, etc.

Solution?

Don’t want to add to staging area, don’t want git to track these

.gitignore (in root of project)

Beware?

If you accidentally add a file to your repository

THEN, add to gitignore, it won’t work

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

How do we remove a file from the staging area that we don’t want git to track?

A

must remove from staging area (index)

$git rm

removes from working directory and staging area

$git rm –cached -r bin/

removes only from staging area (index)

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

What’s a shortcut for status?

Hint: git status -s

A

$git status -s

short version

less wordy

easier on the eyes

Symbols?

M - modified

A - added

left column

staging area

right column

working directory

Ex. red M -> modified a file in working directory, not yet in staging

green M -> some changes in staging area

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

How can we see the exact lines of code we’ve stagged?

Hint: $git diff –staged

A

Best practice - always review changes before commit

Terminal:

$git diff –staged

$git diff

compares what is in working directory vs. staged directory

visual dev tools (VSCode):

$git config –global diff.tool vscode

$git config –global difftool.vscode.cmd “code –wait –diff $LOCAL $REMOTE”

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

How do we setup VScode for viewing differences between files?

Hint: $git difftool –staged

A

$git difftool –staged

ex.

old copy in working directory

vs

old copy in staging area

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

How do we look at history?

Hint: $git log

A

$git log –oneline

newest commit on top

$git log –onlineline –reverse

initial commit on top

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

How do we see the content of a specific commit?

Hint: $git show ~HEAD1

A

$git show commit 7c6df80

$git show HEAD~#steps

$git show HEAD~1:.gitignore

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

How do we see all the files and directories in a commit (not only changes)?

Hint: $git ls-tree HEAD~1

A

directory in filesystem represented as a tree

each directory can have children

children can be files / sub directories

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

How do we remove a file from the staging area?

Hint: $git restore –staged file1.js

A

removes all changes from staging directory

only changes left in the working directory

Restore implementation?

grabs last copy from Git repository

puts that back into staging area (last commit)

if not in Git repository?

Removes from staging

reverts back to untracked file

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

How can we discard changes made in working directory ?

A

undue local changes

$ git restore .

will take previous version from staging area and restore that version in working directory

$ git clean -fd

removes untracked files from working directory

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

How do we restore a file to a previous version?

A

$git restore –source=HEAD~1 fileName

removes file from working directory and staging area

restore file to previous version vs undue commit

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

How do we create snapshots using VScode?

A

Open VScode

go to git extension

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

What is GitKraken?

A

A GUI tool for Git

can see all commits - author, date/time

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

What are we going to learn in the history section?

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

What does $git –oneline –stat do for us?

A

$git –oneline -stat

shows us all the files changed in each commit

$git –oneline –patch

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

How do we filter history of commits when looking at Git repository?

A

In real world, hundreds or thousands of commits

Don’t want to look through them all

filter by author, commit message, date, etc.

GIT COMMANDS:

$git log –oneline -3

returns last three commits

$git log –oneline –author=”arsalon”

returns commits made by author=arsalon

$git log –oneline –after=”2020-08-17”

$git log –oneline –after=”yesterday”

$git log –oneline –after=”one week ago”

returns commits made after specified date

git log –oneline –grep=”GUI”

case sensitive, returns commits with message containing “GUI” term

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

How can we filter history by all commits that have modified a specific function?

Hint: $git log –oneline -S”functionName”

A

Ex.

$ git log –oneline -S”getJwt” –patch

brings up all commits that modify getJwt ( ) and shows changes

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

How do we filter history by a range (within a range)?

Hint: $ git log –oneline commitIdentifier1…commitIdentifier2

A

Example

$ git log –oneline 56a3436..600400c

gives all commits after 56a3436 up to 600400c (included)

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

How do we customize the log output?

Hint: $git log –pretty=format:”%an commited %h on %cd”

A

$ git log –pretty=format:”%an commited %h on %cd”

%an - author name

%h - abbreviated commit identifier

%cd - commit date

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

What are git aliases?

Hint: $git config –global alias.unstage “restore –staged .”

A

$ git config –global alias.lglog –pretty=format:’%Cgreen%an%Creset commited %Cred% %h%Creset% %Cblue% on %cd’“

Can abstract git commands into shorter alias

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

How do we see a specific commit?

Hint $git show HEAD~2

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

How can we see the list of file names that have been changed across commits?

Hint: $git diff HEAD~1 HEAD –name-only

A

$git diff HEAD~2 HEAD –name-status

shows status of files changed (modified, added, etc.)

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

How do we restore our working directory to a particular snapshot from a commit?

(ie. restore all files to a previous snapshot version)

A

$git checkout 6c325d5

working directory will look exactly like an earlier point in time

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

What is a detached head?

A

$git checkout master

restores head to master branch

git When we checkout a particular commit

head will point to that commit

Head isn’t pointing to a branch (master)

it’s pointing to a particular commit

DON’T MAKE CHANGES

ONLY LOOK AROUND

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

What is bisect?

A

GIT COMMANDS:

$git bisect start

$git bisect good ###

$git bisect bad ###

$git bisect reset

an incredibly powerful tool for finding bugs

can quickly find the commit that introduced the issue

How?

Give Git the bad commit code (one with bug)

give Git a good commit code (one without bug)

like binary search (log n )

ref/bisect/bad -> bad commit labeled

(Head) -> in middlepoint between two*

refs/bisect/good -> good commit

*working directory restored to middlepoint snapshot (head)

*run tests to see if issue is still there

*if issue is not there, tell bisect commit is good, continue

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

How do we view an authors contribution to a git repository?

Hint: $git shortlog

A

$git shortlog -n -s -e –before=”” –after ““

-n number of commits (filter author by)

-s suppress commit messages

-e show email address

-before/after to see contributors for certain date rangs

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

How do we view history of a file?

Hint: $git log –oneline –stat fileName.ext

A

$cd

$ls

$git log –oneline –stat index.js

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

How do we restore a deleted file?

$git checkout previousCommit pathName.ext

$git commit -m “restore pathName.ext”

A

How?

Look at parent of file, get ID

checkout only deleted file from commit

Situation?

remove file fixing a bug or implementing a new feature

want to restore the file

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

How do we find the author of a particular line of code?

$git blame filename.ext -L 1, 11

A

$git blame filename.ext -L 1,11

-L lines

1, 11 line 1 through 11

Part of troubleshooting issues, want to know who wrote a line of code

$git blame fileName.ext

in front of each line of code, additional information

commit ID

author name

date/time inserted

Ex.

git blame -e -L 1,11 authService.js

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

What are tags?

$git tag -a v1.1 -m “message”

$git tag -d v1.1

A

allow us to bookmark commits like a certain version

lightweight vs annotated tage

(​light weight tag)

$git tag v1.1 commitID

a reference or pointer to particular commit

(annotated tag)

$git tag -a v1.1 -m “my version 1.1”

$git tag -n

creates annotated tag (object) with properties

can associate a message with tag

$git tag -d tagID

deletes tag

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

What is gitlens?

A

VSCode plugin

Pros

can view commits

can view diff

can compare commits

can see files changed

can search by messages, etc.

Cons

cannot search by multiple criterias

cannot use bisect to find bugs

Mosh Advice

GUI tools are great for diff

seeing how two files are different

54
Q

How do we view history in GitKraken?

A

Can right click, add tags, checkout, view diffs

55
Q

What is branching?

Hint: totally change how you develop software

A

One of the most powerful Git tools

the tools learned in this section

can totally change how I develop software

use branches

to work on a feature in isolation

like a separated isolated workspace

56
Q

How do we use branches to develop features in isolation?

A

without messing with main line of work (master)

work on various work items (features)

after testing and verifying feature works

bring code back to master (merging)

57
Q

What is a branch in git?

A

just a pointer to a commit

tiny file with a 40 char bit ID

Head tracks which branch currently working

Ex.

master branch is just pointer to last commit in main line of work

git moves this pointer forward automatically

58
Q

How do we fix a bug?

A

$git branch bugfix

create a branch to fix bug

$git branch -m oldName newName

rename it to specific bug

Ex. changes only visible in bugfix branch

make changes

$git add .

$git commit -m “fix bug”

$git branch -d branchName

if we switch back to master branch (update head pointer)

won’t see changes

in future, will have to merge branches

delete branch

59
Q

How can we assess how a branch is divering from master?

ie. comparing branches (master w/ sub branch)

A

$git diff bugfix/signup-form

shows differences between current branch and listed branch

when branches are merged can see expected changes

$git diff –name-status bugfix/signup-form

shows on the file that have been changed in branch

$git log master ..branchName

$git log master ..bugfix/signup-form

60
Q

What is stashing?

Hint:

$git stash push -am “message”

$git switch master

$git stash show 1

$git stash apply 1

$git stash drop 1

$git stash clear

A

COMMANDS:

$git stash push -am “message”

$git switch master

$git stash show 1

$git stash apply 1

$git stash drop 1

$git stash clear

When we modify a file in working directory of a branch

and we want to switch to a new branch but have not commited changes

we don’t want to commit because we are not finished

we can stash changes (store in a safe place)

NOTE

new, untracked files are not included in stash (default)

$git stash push -am

to push all files (untracked) into stash

61
Q

What is merging?

A

bringing changes from one branch to another

Two methods:

Fast-forward merge

moving the master pointer to the updated branch

if two branches have not diverged

there is a direct linear path from target to source

Three way merge

if branches have diverged

additional commit that combines versions is created

62
Q

What is a fast-forward merge?

A

bring master pointer forward

if two branches have not diverged

there is a direct linear path from target to source

brings pointer of master forward

Ex. Create a bugfix branch

code is identical to master

make updates/changes to bugfix directory

copy all files from bugfix to master?

if thousands of files??

no additional changes in master

files in master are first version of bugfix

simply, rename bugfix to master

63
Q

What is a three way merge?

A

additional commits on master (after branch)

changes in master that don’t exist in bugfix branch

soln?

git creates a new commit that combines changes from both branches

git looks at before commit and after snapshots (two)

64
Q

How do we create and switch to a branch simultaneously?

A

$ git switch -C bugfix

65
Q

How do we force a merge-commit?

Hint:

$git merge –no-ff bugfix/login-form

A

$git merge –no-ff bugfix/login-form

allows us a true history of a project

allows us to revert back to previous version

66
Q

What’s the benefit of not using a fast-forward merge?

A

new merge commit combines all changes in branch

can revert to an old commit

if using a merge commit, a single commit to revert

vs.

if fast-forward merge, have to undue more commits (two)

67
Q

How do we disable fast-forward merging in the current repository?

A

$git config ff no

Some companies may have a policy of no fast forward merging

68
Q

How do we run a three way merge commit?

$git merge branchName

A

looks at tips (last commit in each branch)

and common ancestor

creates a merge

69
Q

How do we see which branches have already been merged with master?

Hint: $git branch –merged (no–merged)

A

$git branch –merged

shows branches merged

$git branch -d branchName

deletes branch

$git branch –no-merge

shows unmerged branches

Best Practice:

When done with a branch, delete it

otherise pointer will sit / create confusion in future

70
Q

What is a merge conflict?

A

Merge Conflicts:

Same line of code has been changed in different ways in different branches

One branch changes a file, another deletes a file

Two branches add same file twice, content is different in both files

Soln?

goog

71
Q

How do we resolve a merge conflict during a merge commit?

Hint: Don’t add new lines of code during a merge commit

A

VSCode:

open file

click buttons (accept current, accept incoming, accept both, compare)

add file to staging area

commit file to repository (modified)

Manually:

remove markers for head, divider

don’t add new lines of code during merge commit (evil commit)

Third Party Merge Tools

also available for handling merge conflicts

72
Q

What is an evil commit?

A

adding new lines of code during a merge commit

in real world, sometimes not avoidable

AS MUCH AS POSSIBLE, try not to introduce new lines of code

73
Q

What are merge tools?

Hint: if using VScode or GitKraken, don’t need these tools

A

can visually see differences

can toggle between multiple files or conflicts

save changes

add modified file to staging

commit the file

74
Q

How do we abort a merge?

A

$git merge –abort

takes you back to the state before you start the merge

back to a clean state before starting a merge

75
Q

How do we undue a merge?

A

something happens, application breaks, merge unsuccessful

undue the merge

Two options:

remove commit (re-writing history)

okay, if only local, not shared with team

revert commit

create a new commit, cancels all changes in bad commit

76
Q

How can we remove a commit?

Hint: git reset –hard HEAD~1

A

WARNING

only do this if on local repository (haven’t pushed to a team repository)

reset the head

Resetting:

Hard

points head to new snapshot, sets working directory, staging directory to snapshot

all working environments are identical

Mixed

points head to new snapshot, staging directory to snapshot, working directory unchanged

Soft

head pointer points to new snapshot, working/staging directory not updated

77
Q

How do we revert a merge?

Hint: git revert -m 1 HEAD

A

Use if shared history with collaborators.

Creates a new commit reverting merge commit

doesn’t change history

Each merge has two parents:

one on master branch

one on secondary branch

tell git how to revert:

to last commit on master branch

merge commit is on master branch

merge commit should be on master branch also

$git revert -m 1 HEAD

-m 1 = first parent

HEAD = target commit (last commit)

78
Q

What is squash merging?

Hint: git merge –squash branchName

A

$ git merge –squash branchName

$git add.

$git commit -m ““

creates a new commit in stagging area that combines changes from branch into staged files

apply this commit to master

Doesn’t have two parents

Not a merge commit

no reference to the sub branch

just a regular commit added on top of master

not a merge commit

Benefits?

left with a simple, clean history

When to Use?

do not want them to pollute history of master branch

small, short lived branches

bug fixes

use if branch commits are not high quality

features can implement in a few hours / day

make sure to remove target branch!

$git merge –squash branchName

$git branch -D bugfix/photo-upload

79
Q

What is rebasing?

A

can change base of our branch

can base it on latest commit on master

Why?

Creates a direct linear path (fast forward merge)

Cautious?

Rewrites history

only use for local commits

do not use for collaboration

80
Q

What do we do if there is a conflict when rebasing?

A

launch merge tool

resolve conflict

$git rebase –continue

81
Q

What is cherry picking?

$git cherry-pick commitID

A

new commit cherry picked from sub-branch

picking a particular commit from another branch into master

not the entire branch, just a particular commit

82
Q

How do we take a file from another branch and bring it into the current branch?

A

git restoresource=feature/send-emailtoc.txt

restores file in working directory

from latest version in branch specified

83
Q

How do we work with branches in VScode?

A

can view, create, etc branches

can resolve merge conflicts, etc.

can revert commits, etc.

84
Q

What is git graph?

A

VS code plugin

85
Q

How can we use GitKraken for branches?

A

Makes it incredibly easy to manage branches, resolve conflicts

86
Q

What will mosh teach us about collaboration?

A

Super important tools, techniques we must master

Master these tools to collaborate with others

Will use every single day when working with a team

Collab workflows

Push, pull, fetch remote repos

GitHub collab tools - milestones, issues, etc.

contributing to open source projects

87
Q

What is the centralized workflow?

A

workflow used in most private teams

everyone has their local repository

central repository used to synchronize work

if central repository goes down, can work offline in remote repository

can synchronize directly with members (often complex)

Where is central respository?

private server in private network

cloud - github, bitbucket

88
Q

What is integration-manager workflow?

A

used in open source projects

only maintainers have access to push code into central repository

Process?

fork repository

clone on our local machine

make commits

push to fork

maintainer can pull and review

if good, will push to main repository

89
Q

How do we add collaborators in Github?

A

Settings -> manage access -> invite collaborators

90
Q

How do we clone a github repository onto our machine?

A

git clone http://etc

91
Q

What is origin/master?

A

A remote tracking branch

tells us where master branch is in origin

local repository vs. remote repository (history can change independently)

origin/master tells us where master branch is in origin repository

92
Q

Is our local repositry connected to our remote repository?

$git fetch

A

No,

if a change is made in remote repository, local repository is unaware

$git fetch

downloads new commit to our local repository from remote repository

git will download commit / move origin/master forward

to move changes from remote tracking back to local repositry,

merge local branch with origin/master branch

if there is a conflict, resolve like normal

93
Q

How do we bring the changes in our remote repository to our local repository?

A

$git fetch

grabs the current snapshot in origin/main

$git merge origin/main

merges local repository with snapshot from origin/main

94
Q

How do we bring changes from our remote repository into our local repository?

Hint: pull combines two commmands

A

fetch + merge

$git fetch origin

$git merge origin/main

$git pull

combines fetch and merge commands

95
Q

What is pulling?

A

combining fetch and merge commands

$git pull

creates a three way merge commit

pollutes history

$git pull -rebase

creates a rebase action

creates a linear history

96
Q

What is three way merge pull?

A
97
Q

What is a rebase pull?

$git pull –rebase

A

Creates simple, linear history

98
Q

What is the push command?

A

if we have local changes in our repository

push will send them to remote repository

Can be rejected, why?

someone else puts work in the remote repository

First, pull and do a merge (or rebase)

if conflicts, solve them

Then, do a push

99
Q

How do we store github credentials for push requests?

A

keychain

git config –global credential.helper osxkeychain

100
Q

How can we create / store tags in github?

A

very useful, allows us to download entire source file up to that point

101
Q

How do we delete a tag from github?

A

$ git push origin –delete v1.0

deletes tag from repository

$ git tag -d v1.0

deletes tag from local repository

102
Q

What are releases?

A

a gitHub feature

can create release to package software, binary files (compiled version of app), release notes

103
Q

How do we share branches?

Hint: git push -u origin feature/change-password

A

if collaborating on a branch

must explicitly push branch to github

git push -u origin branchName

-u upstream

creates a branch in github

can use it like main branch

push commits, etc.

git push -d origin feature/change-password

deletes from origin

104
Q

How do we work with our remote branches?

Hint: git branch -r

A

first, we fetch a new branch from origin

then, we create a new branch locally that points to origin/main branch

105
Q

How can we collaborate on remote branches?

A

git pull

gets the latest commits on branch from collaborators

git switch main

return to main branch from sub branch

git merge feature/change-password

merge main with feature branch (if finished on feature)

git push

send branch changes merged into main to origin/main

git push -d origin feature/change-password

delete branch from origin repository (remote repo)

git branch -d feature/change-password

delete branch off local repository

Collaborator:

create a local branch

point origin/branch to local branch repository

make commits, push

when finished, merge with main and push

106
Q

How do we remove remote branches that have been deleted from our local repository?

Hint: git remote prune origin

A

last step after a feature branch was merged and deleted from origin

107
Q

What is a pull request?

A

before merging a branch to master

opening a discussion with team mates

Why?

as part of implementing a feature / fixing a bug…

we often need feedback from team

before merging a branch to master

Who closes?

Depends on your team

person who opened it, closes it

person who opened it, doesn’t close it

close + delete on github

then…

$git remote prune origin

$git branch -d feature/login

108
Q

How can we handle conflicts in a pull request?

A

Ex. Masterbranch moves forward, feature branch is behind and conflicted

soln

start pull request

use command line

use github user interface

command line?

same as usual

  1. pull in latest code
  2. start merge process
  3. resolve conflicts
  4. add new commit
  5. push to github

Github?

use the UI

click on resolve conflicts

click submit

click merge

done!

109
Q

What is issue tracking?

A

Goes hand and hand with pull requests

can track…

bug fixes

new features

enhancements

ideas on the team

Why?

all details for working on an issue encapsulated in a single place

much better than using email

can assign to team members

can have a conversation about the issue on the github issue page

can link to a pull request

can assign to a milestone

can come in and pickup a new issue / assign to self

110
Q

What can we do in our issue tracking?

A

create custom lables:

refactoring, etc.

github provides a standard / custom labels

111
Q

What are milestones?

A

track progress of various issues

add issues to milestone

see progress in milestone

assign issues to a milestone

Ex. V2.0 of Software release

as issues are completed

milestone progress is updated

112
Q

What are we going to learn in rewriting history?

A

great but dangerous features

re-write history

rewrite, drop, combine, split commits, etc.

113
Q

Why do we need history?

A

Extact meaningful information from history

See what was changed

why and when it was changed

114
Q

Why do we need to rewrite history?

A

if we have bad history,

cannot extract meaningful information

re-write to create a meaningful story

Bad history:

commit messages are not meaningful

commits are too large

commits contain unrelated changes

commits are too small or scattered all over history

115
Q

How can we make clean, meaningful history?

Hint: re-write bad history

A

too small commits

squash related commits together

too large commits

split large commits into small commits with each being a logical chain

poor messages on commits

reword commits

accidental commits

drop commits

commits not representing logical steps

can modify contents of commits - add file, etc.

116
Q

What’s the golden rule of re-writing history?

Hint: don’t re-write public history

A

if pushed commits to public repository (origin)

don’t re-write!

why?

if you replace a commit someone has checked out, going to get issues

will make history look noisy

only re-write private history!

It’s a good practice

clean up private history before sharing with the world

117
Q

What’s a good practice?

A

clean up history in private

then push to world

history should tell a story

118
Q

What’s wrong with this history?

A

poor commit message

ommited the word “on”

render restaurants ON the map

Small commits

Fix a typo - this shouldn’t be a commit

change color of restaurant icons - should be combined with prev commit

WIP - this is just noise in history, drop or change message

Update terms of service and Google SDK - combining two logic steps together, split into two commits

. - mysterious commit, drop or change message

119
Q

How do we undue a commit?

Hint: git reset –hard HEAD~1 (removes history)

A

Locally only?

git reset –hard HEAD~1

removes from history

-soft removes commit only, working/local untouched, working can commit

-mixed removes changes in staging area

-hard discard local changes

120
Q

How can we revert last three commits?

Hint: git revert –no-commit HEAD~3..

A

creates a new commit that undoes last three commits

use if history is public already

$ git revert –no-commit HEAD~3

$ git revert –continue

$ git revert –abort (if bad)

121
Q

How do we recover lost commits?

Hint:

$git reflog

$git reset –hard HEAD@{1}

A

$ git reflog

$git reset –hard HEAD@{1}

git stores commits in project

after a while, garbage collects them

122
Q

How do we modify a commit?

$git commit –amend -m

A

commits on git are immutable

even though on surface, ammeding a commit

git is actually creating a new commit

123
Q

How can we remove a commit?

$git reset –mixed HEAD~1

A

working directory is dirty

mixed

points head to commit before last

puts that snapshot in staging area

working directory is still dirty

Soln?

git reset –mixed HEAD~1

git clean -fd

removes untracked files from working directory

124
Q

How can we ammend an earlier commit?

$ git rebase -i commitID

$ git commit –amend

A

interactive rebasing

re-writes history

have to re-create other commits along the chain

How?

$ git rebase -i commitID

open in editor, change specific commit to “edit”

make modifications

$ git commit –amend

Process?

creates a separate branch

all changes made from commit will be played on top of commit

changes are carried on across subsequent commits

branch will be discarded

125
Q

How do we drop a commit?

A

start rebase with parent of commit (want to drop)

Problem?

if this commit introduced a new file, next commit modifies it

will be a conflict

changes from deleted commit, added to subsequent commit

126
Q

How do we reword commit messages?

Hint: git rebase -i commit~1

A

change message to reword

git will pull up commit, allow us to change message

all subsequent commits are re-created

re-writes history

only do with private repository!

127
Q

How do we reorder commits?

Hint: git rebase -i commit

A

git rebase -i commit

move up in VScode

128
Q

How do we squash commits?

Hint: git rebase -i

A

combine commits

129
Q

How can we split a commit?

A

git rebase -i commitParent

opens VS code, click edit, close

brings edit snapshot to working dir / staging dir

git reset –soft HEAD~1

moves head to one step before target commit

changes in staging area, can unstage some, make separate commits

git reset –mixed HEAD^

130
Q

How can we re-write history in gitkracken?

A