Git Workflow Flashcards
(git) Create a git repository
git init
(git) Stage files, additions, changes and deletions
How do you add multiple files?
How do you add all files?
git add [directories do all containing files]
filenames separated by a space
git add –all
(git) Display status of changes and stages
git status
(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?
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.
(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
safe
git branch branchname -d
force
git branch branchname -D
Can’t do it
(git) log everything and display it visually
git log –all –graph
(git) Commit
git commit -m “comment”
Commits, -m sets the commit’s message
(git) Create a new branch at head
What happens if it’s the same name as another branch?
git branch newBranchName
If branch name already exists it will give error
(git) List all the branches
git branch
or
git branch –list
(git) Move the head and change local files to match the specific commit
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
(git) Delete a commit or multiple commits
Keep files as is on computer
OR
reset files too
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
(git) Undo a commit into a new commit
git revert commitID
Undoes the specific commit. Does this into a new commit at HEAD.
(git) Merge a branch into the current branch into a new commit
What happens with a conflict?
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.
(git) What is a branch?
What happens if you’re outside a branch?
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.
(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?
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.
(git) Stage all changes
Stage all changes files and deletions but not additions
git add -A or git add .
git add -u
(git)
Connect an already existing local repo to github
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
(git) What is upstream and downstream?
Generally, upstream is from where you clone the repository, and downstream is any project that integrates your work with other works.
(git)
Create local repo from remote repo:
Pull from github along with all commits and information.
push changes
pull changes
git clone https://github.com/agarjesse/TestRepo
git push origin
(github uses origin as alias)
git pull origin
(git) Change current branch name
git branch -m newName
(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?
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?
(git)
What does git fetch do?
Why not just git pull?
What is best practice?
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
(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
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
What is git
Version control program
Difference between text editor and git in terms of save functionality
A text editor can only make and save changes to a file.
Git tracks changes to the files and their contents over time.
Does git work local or remote or both?
Local
Does github work at local, remote or both?
Remote
Why is git and github useful for teams?
Can work on separate code and use git and github to combine changes.
git log vs git status
Log gives log of commits
Status gives status of changes and stages
Add vs commit
Add is like choosing what you want to capture
Commit is capturing it in git
What is origin?
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.
Explain what main is in git push origin main.
In Git, main is the branch of the remote repository you want to push your changes to.
Main is the default branch
Display URL for github repo
git remote -v
[incomplete} Describe the basic git workflow in terms of:
- Creating
- Cloning Remote
- Pushing
- Main vs origin
incomplete
7 git commit message rules and explanations
- 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.
- Subjext line limit 50 cars
- Capitalize the Subject Line Like a Title
- Do not end subject line with period
- 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
- Wrap the body at 72 characters
- Body explains what and why (not how)
How many changes should you make per commit?
As few as possible
1 if possible
What are some ways to make sure commit messages are short
character count in vs code along the bottom