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
**What's** a **shortcut for status**? **Hint:** git status -s
**$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
26
**How can** we see the **exact lines of code we've stagged**? Hint: **$git diff --staged**
**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"
27
**How do we setup VScode** for **viewing differences between files?** **Hint:** $git difftool --staged
**$git difftool --staged** ex. **old copy in working directory** vs **old copy in staging area**
28
**How do we look at history?** **Hint**: $git log
**$git log --oneline** **newest commit on top** **$git log --onlineline --reverse** **initial commit on top**
29
How do we **see the content of a specific commit?** ## Footnote **Hint: $git show ~HEAD1**
$git show commit 7c6df80 $git show HEAD~#steps $git show HEAD~1:.gitignore
30
How do we **see all the files and directories in a commit** (not only changes)? **Hint**: $git ls-tree HEAD~1
directory in **filesystem represented as a tree** ## Footnote **each directory can have children** **children can be files / sub directories**
31
**How d**o we **remove a file from the staging area?** ## Footnote **Hint: $git restore --staged file1.js**
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
32
**How can** we **discard changes made in working directory ?**
**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
33
**How** do we **restore a file to a previous version**?
**$git restore --source=HEAD~1 fileName** **removes file** from **working directory** and **staging area** **restore file to previous version vs undue commit**
34
How do we **create snapshots using VScode**?
Open VScode go to git extension
35
What is GitKraken?
A GUI tool for Git can see all commits - author, date/time
36
**What** are we **going to learn in the history section?**
37
**What** does **$git --oneline --stat do for us**?
**$git --oneline -stat** **shows us** all the **files changed in each commit** **$git --oneline --patch**
38
**How** do we **filter history of commits** when **looking at Git repository?**
**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
39
**How can** we **filter history** by **all commits that have modified a specific function?** **Hint**: $**git log --oneline -S"functionName"**
Ex. $ **git log --oneline -S"getJwt" --patch** **brings up all commits** that **modify getJwt ( )** and **shows changes**
40
**How** do we **filter history** by **a range (within a range)?** **Hint:** $ **git log --oneline commitIdentifier1...commitIdentifier2**
**Example** $ **git log --oneline 56a3436..600400c** **gives all** commits after **56a3436 up to 600400c (included)**
41
**How** do we **customize the log output?** **Hint:** **$git log --pretty=format:"%an commited %h on %cd"**
**$ git log --pretty=format:"%an commited %h on %cd"** **%an** - author name **%h** - abbreviated commit identifier **%cd** - commit date
42
**What** are **git aliases?** **Hint: $**git config --global alias.unstage "restore --staged ."
$ **git config --global alias.lg**"**log --pretty=format:'%Cgreen%an%Creset commited %Cred% %h%Creset% %Cblue% on %cd'"** Can **abstract** git commands into **shorter alias**
43
**How** do we **see a specific commit?** **Hint** $git show HEAD~2
44
**How** can we **see the list of file names** that have been **changed across commits?** **Hint**: **$git diff HEAD~1 HEAD --name-only**
**$git diff HEAD~2 HEAD --name-status** shows status of files changed (modified, added, etc.)
45
**How** do we **restore our working directory** to a **particular snapshot from a commit**? (ie. **restore all files** to a **previous snapshot version**)
$**git checkout** 6c325d5 **working directory** will **look exactly like an earlier point in time**
46
**What** is a **detached head**?
**$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**
47
**What is bisect?**
**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**
48
**How** do we **view an authors contribution** to a **git repository**? **Hint**: **$git shortlog**
**$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**
49
**How** do we **view history of a file?** **Hint**: **$git log --oneline --stat fileName.ext**
$cd $ls **$git log --oneline --stat index.js**
50
**How** do we **restore a deleted file?** ## Footnote **$git checkout previousCommit pathName.ext** **$git commit -m "restore pathName.ext"**
**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**
51
**How** do we **find the author** of a **particular line of code?** **$git blame filename.ext -L 1, 11**
**$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**
52
**What** are **tags**? **$git tag -a v1.1 -m "message"** **$git tag -d v1.1**
**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**
53
**What is gitlens?**
**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
**How** do we **view history in GitKraken?**
Can **right click, add tags, checkout, view diffs**
55
**What** is **branching**? **Hint:** totally change how you **develop software**
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
**How** do we **use branches** to **develop features in isolation**?
**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
**What** is a **branch in git?**
**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
**How** do we **fix a bug?**
**$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
**How** can we **assess how a branch is divering from master?** ie. **comparing branches** **(master w/ sub branch)**
**$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
**What** is **stashing?** ## Footnote **Hint:** **$git stash push -am "message"** **$git switch master** **$git stash show 1** **$git stash apply 1** **$git stash drop 1** **$git stash clear**
**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
**What** is **merging?**
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
**What** is a **fast-forward merge**?
**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
**What** is a **three way merge**?
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
**How** do we **create and switch** to a **branch simultaneously**?
**$ git switch -C bugfix**
65
**How** do we **force a merge-commit**? Hint: **$git merge --no-ff bugfix/login-form**
**$git merge --no-ff bugfix/login-form** **allows us a true history of a project** **allows us to revert back to previous version**
66
**What's** the **benefit of not using** a **fast-forward merge**?
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
**How** do we **disable fast-forward merging** in the **current repository?**
**$git config ff no** **Some companies** may **have a policy of no fast forward** merging
68
**How do** we **run a three way merge commit?** ## Footnote **$git merge branchName**
**looks at tips** (last commit in each branch) and **common ancestor** **creates a merge**
69
**How do** we see **which branches have already been merged** with **master**? **Hint:** $git branch --merged (no--merged)
$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
What is a **merge conflict?**
**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
**How do** we **resolve a merge conflict during a merge commit?** **Hint:** Don't add new lines of code during a merge commit
**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
**What** is an **evil commit?**
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
**What** are **merge tools**? **Hint:** if using **VScode or GitKraken**, don't **need these tools**
can **visually see differences** can **toggle between multiple files or conflicts** **save changes** **add modified file to staging** **commit the file**
74
**How** do we **abort a merge?**
**$git merge --abort** takes you **back to the state** **before** you **start the merge** **back to a clean state before starting a merge**
75
**How** do we **undue a merge**?
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
**How can** we **remove a commit**? **Hint:** git reset --hard HEAD~1
**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
**How** do we **revert a merge**? **Hint:** git revert -m 1 HEAD
**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
What is **squash merging?** **Hint: git merge --squash branchName**
**$ 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
**What** is **rebasing?**
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
**What** **do we do** if **there is a conflict** when **rebasing**?
**launch merge tool** resolve conflict **$git rebase --continue**
81
**What** is **cherry picking**? ## Footnote **$git cherry-pick commitID**
**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
**How** do we **take a file from another branch** and **bring it into the current branch?**
**git restore** --**source**=**feature/send-email** --**toc.txt** restores **file in working directory** from **latest version in branch specified**
83
**How** do we **work with branches in VScode**?
can **view, create, etc branches** can r**esolve merge conflicts, etc.** **can revert commits, etc.**
84
**What** is **git graph**?
**VS code plugin**
85
**How can we use** **GitKraken for branches?**
**Makes** it **incredibly easy** to **manage branches**, **resolve conflicts**
86
**What will mosh teach us about collaboration?**
**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
**What** is the **centralized workflow**?
**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
**What** is **integration-manager workflow**?
**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
**How** do we **add collaborators** in **Github?**
**Settings -\> manage access -\> invite collaborators**
90
**How** do we **clone a github repository** onto **our machine**?
**git clone** http://etc
91
**What** is **origin/master?**
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
Is our **local repositry connected** to our **remote repository**? $git fetch
**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
**How** do we **bring the changes** in our **remote repository** to our **local repository**?
$git fetch **grabs** the **current snapshot in origin/main** $git merge **origin/main** **merges local repository with snapshot from origin/main**
94
**How** do we **bring changes** from our **remote repository into our local repository**? **Hint**: pull combines two commmands
fetch + merge $git fetch origin $git merge origin/main **$git pull** combines fetch and merge commands
95
**What** is **pulling**?
**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
**What** is **three way merge** **pull?**
97
**What** is a **rebase pull?** ## Footnote **$git pull --rebase**
Creates simple, linear history
98
**What** is the **push command?**
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
**How** do **we store** **github credentials** for **push requests?**
**keychain** **git config --global credential.helper osxkeychain**
100
**How** can we **create / store tags** in **github**?
**very useful,** allows us to **download entire source file** up **to that point**
101
**How** do we **delete a tag from github**?
**$ git push origin --delete v1.0** deletes tag from repository **$ git tag -d v1.0** deletes tag from local repository
102
**What** are **releases**?
a **gitHub feature** can **create release to package software, binary files (compiled version of app), release notes**
103
**How** do we **share branches**? **Hint: git push -u** **origin feature/change-password**
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
**How** do we **work with our remote branches**? **Hint:** git branch -r
**first**, we **fetch a new branch from origin** **then**, we **create a new branch locally that points to origin/main branch**
105
How can **we collaborate on remote branches**?
**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
**How** do we **remove remote branches** that have **been deleted** from **our local repository**? **Hint**: git remote prune origin
**last step** after a **feature branch** was **merged and deleted** from **origin**
107
**What** is a **pull request**?
**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
**How** can we **handle conflicts** in a **pull request?**
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
**What** is **issue tracking?**
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
**What** can **we do** in **our issue tracking**?
**create custom lables:** **refactoring,** etc. **github** provides **a standard / custom labels**
111
**What** are **milestones?**
**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
**What** are **we going to learn** in **rewriting history**?
great but dangerous features **re-write history** rewrite, drop, combine, split commits, etc.
113
**Why** do we **need history?**
Extact **meaningful information** from **history** See **what was changed** **why** and **when it was changed**
114
**Why** do we **need to rewrite history?**
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
**How** can we **make clean**, **meaningful history**? **Hint**: re-write bad history
**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
**What's** the **golden rule** of **re-writing history?** **Hint:** don't re-write **public history**
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
**What's** a **good practice?**
**clean up history** in **private** then **push to world** **history should tell a story**
118
What's **wrong** with **this history**?
**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
**How** do we **undue a commit?** ## Footnote **Hint: git reset --hard HEAD~1 (removes history)**
**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
**How** can we **revert** last **three commits?** **Hint:** git revert --no-commit HEAD~3..
**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
**How** do we **recover lost commits?** ## Footnote **Hint:** **$git reflog** **$git reset --hard HEAD@{1}**
**$ git reflog** **$git reset --hard HEAD@{1}** **git** stores **commits in project** **after a while**, garbage **collects them**
122
**How** do we **modify a commit**? $git commit --amend -m
**commits** on **git** are **immutable** even **though on surface**, **ammeding a commit** **git** is **actually creating a new commit**
123
**How** can we **remove a commit**? $git reset --mixed HEAD~1
**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
**How** can **we ammend** an **earlier commit**? $ git rebase -i commitID $ git commit --amend
**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
**How** do we **drop a commit?**
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
**How** do we **reword commit messages?** **Hint:** git rebase -i commit~1
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
**How** do we **reorder commits?** **Hint:** git rebase -i commit
**git rebase -i commit** **move up in VScode**
128
**How** do we **squash commits?** ## Footnote **Hint: git rebase -i**
combine commits
129
**How** can we **split a commit?**
**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
**How** can we **re-write history in gitkracken?**