-
What are the four different phases of
git
that we’ve learned? What commands do you know to move changes from one phase to the next? Is there ever more than one way to move a change from one phase to another? -
What is the difference between
git status
andgit log
? -
One popular “version control” that you’ve probably used is Google Drive/Docs. How is this similar to git? How is it different?
-
Let’s
git
some practice! Start by downloading some files:wget https://courses.cs.washington.edu/courses/cse391/25su/lectures/4/questions4.zip unzip questions4.zip
There should now be a directory
questions4/recipes
- this is actually a git repository!Note
You don’t typically want to distribute
git
repos in a zip file (we’ve done this just for convenience). In reality, you should host your git repositories somewhere like GitHub or GitLab and download them viagit clone
.cd
into thequestions4/recipes
repo, and then complete the following tasks:-
Add a third step to the
sundae.txt
recipe:-
Checkout a new branch (give it a descriptive name).
-
Add a third step to
sundae.txt
with any addition you want to make to the sundae. -
Stage, and then commit your changes. Normally you’d want to push your branch/changes too, but we will skip this step for this exercise.
-
Merge your branch into
main
. Make sure you understand which branch you should be on to perform the merge operation. Again, skip pushing your changes. -
When you are done, you should be able to see
main
pointing to your new commit, and a parent commitAdd initial sundae recipe
. What commands can you run to check this?
-
-
There is a branch
add-strawberries
with some changes tosundae.txt
:-
Try to merge
add-strawberries
into your newmain
-
The merge should fail due to a merge conflict. Why does this merge conflict exist? It may be helpful to view the commit graph of the repo (e.g.
git log --all --graph --oneline
) -
Resolve the merge conflict by editing the
sundae.txt
file. You’ll want to keep both your change and the strawberries change, and update the numbers accordingly. Be sure to remove the merge conflict metadata from the file! Once you’re done editingsundae.txt
, make sure you “finish” resolving the merge conflict. -
If you’re successful,
main
should be pointing at a commit titledMerge branch 'add-strawberries'
(assuming you didn’t modify the default merge commit).
-
-
-
What is the command to show the changes between our working directory and our staging area? How about between our staging area and the local repository?
-
Suppose you’re in a random directory on your computer and you want to check if it’s a
git
repository. How might you check this, without using anygit
commands? -
As you grow more experienced with
git
you’ll find yourself typing a lot of long commands which can be cumbersome. Luckily for us,git
allows to alias many of the commands we run so we can rename them. So, for example, let’s say we want to aliasstatus
to simplyst
. If we wanted to do this for allgit
repositories on our computer, we could typeOr, if we want to alias this for just thegit config --global alias.st status
git
repository we’re currently using:Write your own global alias forgit config alias.st status
commit
that makes sense for you! -
Caution
The command we’re about to discuss can be very dangerous. Use this at your own risk, but it can be very useful if used correctly!
The
git reset
command allows us to move changes out of a commit and back into the staging area. However, this command can be very dangerous if you’ve already pushed your changes to remote. Can you think of why this would cause problems? What might be a good rule of thumb for when to use something likegit reset
?