Exercises Git Advanced#
1 Explaining options#
What do the
--onelineand-noptions forgit logdo?What other options does
git loghave 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..sameshow? (Try to answer the question before running the command.)What will
git merge same maindo? (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
experimentbranch usinggit branch -d experiment? Why?What option can you give Git to delete the
experimentbranch? 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.mdfile 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.txtto themasterbranch of their desktop repository and pushes that change to their repository on GitHub.Fuchsia creates a pull request from the
mainbranch of their repository on GitHub to themainbranch of Chartreuse’s repository on GitHub.Chartreuse does not merge Fuchsia’s PR. Instead, they add a file
chartreuse.txtto themainbranch of their desktop repository and push that change to their repository on GitHub.Fuchsia adds a remote to their desktop repository called
upstreamthat points at Chartreuse’s repository on GitHub and runsgit pull upstream main, then merges any changes or conflicts.Fuchsia pushes from the
mainbranch of their desktop repository to themainbranch of their GitHub repository.Chartreuse merges Fuchsia’s pull request.
Chartreuse runs
git pull origin mainon the desktop.