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.