Git Workflow Flashcards

You may prefer our related Brainscape-certified flashcards:
1
Q

(git) Create a git repository

A

git init

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

(git) Stage files, additions, changes and deletions

How do you add multiple files?

How do you add all files?

A

git add [directories do all containing files]

filenames separated by a space

git add –all

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

(git) Display status of changes and stages

A

git status

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

(git) Move HEAD to either the newest part of the branch or to that specific commit and change files in the directory to match that of the specific commit

What happens if you’re not with a branch pointer?

A

git checkout branchname/commitID

You enter detached head:
Detached head:
can checkout things from before, commit and such. But it’s all based on individual commit IDs. So you can very easily get lost. Unless if you’re actively keeping track of those commit ids. Which you’re not going to do.
If you want to try things out, make a new branch.

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

(git) Delete a branch safely meaning to prompt if things haven’t been merged

Delete a branch not caring about saving what’s been done

What happens if you try to delete while in a branch

A

safe
git branch branchname -d

force
git branch branchname -D

Can’t do it

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

(git) log everything and display it visually

A

git log –all –graph

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

(git) Commit

A

git commit -m “comment”

Commits, -m sets the commit’s message

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

(git) Create a new branch at head

What happens if it’s the same name as another branch?

A

git branch newBranchName

If branch name already exists it will give error

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

(git) List all the branches

A

git branch
or
git branch –list

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

(git) Move the head and change local files to match the specific commit

A

git checkout branchname/commitID
Move HEAD to either the newest part of the branch or to that specific commit.
Changes files in the directory to match that of the specific commit

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

(git) Delete a commit or multiple commits
Keep files as is on computer
OR
reset files too

A

git reset commitID
Or
git reset branchName~2

(using a relative value -2 before the “current” tag)
Resets the repository back to a previous state undoing all in commits between a branch tip and target commit.
But keeps files on computer

git reset commitID –hard
Resets repo and files on computer

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

(git) Undo a commit into a new commit

A

git revert commitID

Undoes the specific commit. Does this into a new commit at HEAD.

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

(git) Merge a branch into the current branch into a new commit

What happens with a conflict?

A

git merge targetbranch

If a file has conflicting content, both content is merged into 1 file in an annoying format.
But you then have the opportunity to see the differences, make changes, then commit again.
Or you can cancel the merge.

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

(git) What is a branch?

What happens if you’re outside a branch?

A

A branch is basically just an id that moves with commits.
a lightweight movable pointer to one of these commits

You get a detached head
You don’t need a branch but unbranched arms do not get logged and have really long random IDs.

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

(git) Remove a file from staged
Remove all files from staged

Undo changes you’ve made reverting back to the current commit

How does reverting back to the current commit interact with new files?

File deletes?

A

git restore –staged filename
git restore –staged .

git restore filename
git restore .

It doesn’t restore the absence of files because they are not a part of the repo they are not tracked or restored at all.

It brings back deleted files.

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

(git) Stage all changes

Stage all changes files and deletions but not additions

A

git add -A or git add .

git add -u

17
Q

(git)

Connect an already existing local repo to github

A

Connect local and remote repo, another workflow
Create a remote repo ID

Set the upstream branch

Push to github

push new changes

pull changes

git remote add Chosen_Repo_Alias https://github.com/cubeton/mynewrepository.git
Most choose “origin” alias for central repo

git push –set-upstream TestRepo anotherbranch

git push Chosen_Repo_ID branch_ID
omit branchID to just push head

git pull Chosen_Repo_ID Branch_ID_to_pull_into

18
Q

(git) What is upstream and downstream?

A

Generally, upstream is from where you clone the repository, and downstream is any project that integrates your work with other works.

19
Q

(git)
Create local repo from remote repo:
Pull from github along with all commits and information.

push changes

pull changes

A

git clone https://github.com/agarjesse/TestRepo

git push origin
(github uses origin as alias)

git pull origin

20
Q

(git) Change current branch name

A

git branch -m newName

21
Q

(git)
Link existing local and remote repo, LS workflow:
Create a local repo

Create a github repo

Add remote repo as a known repo

Push to remote repo

Download remote repo info

Compare differences between local and remote repo

Pull from remote

Do you need to define a branch for push and pull?

A

git init

new repo on github website

git remote add alias github_URL

git push -u origin master
-u sets the default upstream repo, the repo where push and pull will go

git fetch

git diff origin/master master

git merge
launch school uses: (git pull –ff-only)

Maybe depends on whether you’ve set upstream branch?

22
Q

(git)
What does git fetch do?

Why not just git pull?

What is best practice?

A

git pull combines git fetch and git merge.

it woulnd’t let you see the changes first.

best practice is:
git fetch
git diff
git merge

23
Q

(git)
Three ways of reverting:
Undoes changes into a new commit

Changes current files to the current/most-recent commit
and can remove staged

Changes repo commits without changing local files

A

git revert
undoes changes into a new commit

git restore
restores current files to current commit
git restore –staged .
removes staged

git reset
git reset commitID
resets repo commits without changing local files
Or
git reset branchName~2 git reset
resets repo commits without changing local files

24
Q

What is git

A

Version control program

25
Q

Difference between text editor and git in terms of save functionality

A

A text editor can only make and save changes to a file.

Git tracks changes to the files and their contents over time.

26
Q

Does git work local or remote or both?

A

Local

27
Q

Does github work at local, remote or both?

A

Remote

28
Q

Why is git and github useful for teams?

A

Can work on separate code and use git and github to combine changes.

29
Q

git log vs git status

A

Log gives log of commits

Status gives status of changes and stages

30
Q

Add vs commit

A

Add is like choosing what you want to capture

Commit is capturing it in git

31
Q

What is origin?

A

is a placeholder name for the URL of the remote repository

use origin to access the remote repository without having to enter a full URL every time.

32
Q

Explain what main is in git push origin main.

A

In Git, main is the branch of the remote repository you want to push your changes to.
Main is the default branch

33
Q

Display URL for github repo

A

git remote -v

34
Q

[incomplete} Describe the basic git workflow in terms of:

  • Creating
  • Cloning Remote
  • Pushing
  • Main vs origin
A

incomplete

35
Q

7 git commit message rules and explanations

A
  1. Separate subject from body with a blank line- the git commit message is just a text field. Line one will become the subject line. Leave a space. Then add more detailed info.
  2. Subjext line limit 50 cars
  3. Capitalize the Subject Line Like a Title
  4. Do not end subject line with period
  5. Use Imperative Mood
    It’s the most parsimonious
    A properly formed Git commit subject line should always be able to complete the following sentence:

If applied, this commit will: [your subject line here]
For example:

(If applied, this commit will) refactor subsystem X for readability
(If applied, this commit will) update getting started documentation
(If applied, this commit will) remove deprecated methods
(If applied, this commit will) release version 1.0.0
(If applied, this commit will) merge pull request #123 from user/branch

  1. Wrap the body at 72 characters
  2. Body explains what and why (not how)
36
Q

How many changes should you make per commit?

A

As few as possible

1 if possible

37
Q

What are some ways to make sure commit messages are short

A

character count in vs code along the bottom