Exercises Git Advanced#
1 Explaining options#
What do the
--oneline
and-n
options forgit log
do?What other options does
git log
have that you would find useful?
2) Modifying prompt#
Modify your shell prompt so that it shows the branch you are on when you are in a repository.
3) Ignoring files#
GitHub maintains [a collection of .gitignore
files][github-gitignore]
for projects of various kinds.
Look at the sample .gitignore
file for Python:
how many of the ignored files do you recognize?
Where could you look for more information about them?
4) Creating the same file twice#
Create a branch called same
.
In it, create a file called same.txt
that contains your name and the date.
Switch back to main
.
Check that same.txt
does not exist,
then create the same file with exactly the same contents.
What will
git diff main..same
show? (Try to answer the question before running the command.)What will
git merge same main
do? (Try to answer the question before running the command.)
5) Deleting a branch without merging#
Create a branch called experiment
.
In it, create a file called experiment.txt
that contains your name and the date,
then switch back to master
.
What happens when you try to delete the
experiment
branch usinggit branch -d experiment
? Why?What option can you give Git to delete the
experiment
branch? Why should you be very careful using it?What do you think will happen if you try to delete the branch you are currently on using this flag?
6) Tracing changes#
Chartreuse and Fuchsia are collaborating on a project. Describe what is in each of the four repositories involved after each of the steps below.
Chartreuse creates a repository containing a
README.md
file on GitHub and clones it to their desktop.Fuchsia forks that repository on GitHub and clones their copy to their desktop.
Fuchsia adds a file
fuchsia.txt
to themaster
branch of their desktop repository and pushes that change to their repository on GitHub.Fuchsia creates a pull request from the
main
branch of their repository on GitHub to themain
branch of Chartreuse’s repository on GitHub.Chartreuse does not merge Fuchsia’s PR. Instead, they add a file
chartreuse.txt
to themain
branch of their desktop repository and push that change to their repository on GitHub.Fuchsia adds a remote to their desktop repository called
upstream
that points at Chartreuse’s repository on GitHub and runsgit pull upstream main
, then merges any changes or conflicts.Fuchsia pushes from the
main
branch of their desktop repository to themain
branch of their GitHub repository.Chartreuse merges Fuchsia’s pull request.
Chartreuse runs
git pull origin main
on the desktop.