Table of Contents
Overview
You will need to become proficient in the use of GIT for managing source code files. It turns out to be very complex (and powerful). As such, don’t be worried that it is taking quite some time to feel comfortable with it. You will find yourself constantly referring to reference materials for a while.
Install
sudo apt install git
Lecture
On May 6, 2020 we had a Zoom-based Git Tutorial by Prof Nelson. The video is embedded below and you can find the Zoom chat transcript here.
Timestamps
0:00 Introduction to Git
3:03 Initializing a Git repository
4:10 Checking the status of your repository
4:40 Adding files to your repository
5:38 .gitignore files
8:05 .gitconfig files
9:20 Committing changes
14:32 Going back to previous commits
18:36 Using “git diff”
22:00 Branching
27:15 Merging
30:07 Cloning repositories
32:09 Group usage of Git with GitHub
Follow-Up Activities
Git is one of those things that you can only read so much about until you really start using it for a project, which is when you will get good with it. Thus, it probably merits only a few hours’ work to get familiar with it.
Try the Basics
Re-watch the video from above and replicate the basic steps you see there with some files of your own (make a copy into a new directory so you don’t mess with your existing good copies):
- Initialize a new repository.
- Add some files to it, and commit them.
- Change one or more of them, see what has changed with “git status”, see the changes with “git diff”, and commit the changes.
- Check the history with
git log
.- What other features does git log offer? For example, try it with
--stat
.
- What other features does git log offer? For example, try it with
- Add a .gitignore file to the repo and commit it.
- Can you have multiple .gitignore files in your repo?
- When you add an entry in a .gitignore file, is it recursive? Ie, are all files in the repo that match the entry ignored, or only those in the current directory? Can you ignore files only in the current directory (not recursive)?
ACTIVITY
▼
Match the git log feature on the left with its corresponding functionality on the right
- -(number)
- --reverse
- --parents
- --graph
- --skip=(number)
- --grep=(pattern)
- Limit the number of commits to output
- Output the commits chosen to be shown in reverse order
- Print also the parents of the commit
- Draw a text-based graphical representation of the commit history on the left hand side of the output
- Skip (number) commits before starting to show the commit output
- Limit the commits output to ones with log message that matches the specified pattern (regular expression)
Use git log --help
Learn About Git Aliases
- Find some handy git aliases online.
- Handy git aliases: https://betterdev.blog/handy-git-aliases/
- Making pretty
git log
outputs: https://stackoverflow.com/questions/1057564/pretty-git-branch-graphs - Awesome git aliases (including dad jokes): https://davidwalsh.name/awesome-git-aliases
- Advanced aliases using shell commands: https://www.atlassian.com/blog/git/advanced-git-aliases
- Set some of these aliases in ~/.gitconfig and try them out for yourself!
Play With Branches
- Create a new branch and then check it out.
- Check what branch you are on by noting where it shows up in
git status
. Also see whatgit branch
tells you. - Now, change a file and recommit.
- Merge the branch’s changes back into master (you must checkout master to do this since a merge is always “merge something else into my current version”)
- Look at the change log again to see how master vs. your branch are represented.
- See the diffs between your current version and some previous version from the change log history (use the first few characters of the big hash value for that other version as the identifier)
- See the diffs between your current version and what is in some other branch (as identified by the branch name)
Merging and Conflicts
- Experiment with merging between branches.
- Can you forcibly create a conflict?
- If you start a merge and run into a conflict, how do you back out and abort?
- Get comfortable with the steps to resolve a conflict.
Fun With Remotes
- Clone a repo from Github. You could try:
- The bootcamp website: https://github.com/byu-cpe/ComputingBootCamp
- The ECEN 330 student repo: https://github.com/byu-cpe/ecen330_student
- Want to look at something with lots of branches, issues, PRs? https://github.com/verilog-to-routing/vtr-verilog-to-routing
- Check what branches you have locally. Can you view all the remote branches locally?
- Can you have multiple remotes? Why would you want to do that?
Git Merge vs Rebase
Learn about merge vs rebase:
- https://www.youtube.com/watch?v=CRlGDDprdOQ
- https://stackoverflow.com/questions/804115/when-do-you-use-git-rebase-instead-of-git-merge
Git GUI Tools
There are many great tools to visualize your Git repositories and histories. Try one out.
Git is Always Changing
- https://stackoverflow.com/questions/57265785/whats-the-difference-between-git-switch-and-git-checkout-branch
- https://github.blog/2020-07-27-highlights-from-git-2-28/#introducing-init-defaultbranch
To Learn More
There are hundreds of printed tutorials on the web, find some and read them. Here are some we have found:
Certify Your Skills
For those who believe they have mastered Git, we present the Git badge! This badge can be viewed in its entirety on Badgr.com here: Git Badge. The Git badge can be used to prove your Git knowledge to potential employers, educational institutions, or anyone else! To earn it, you’ll have to complete the Git test and use your knowledge to perform Git commands for various situations. Attempt the Git test and earn the Git badge with the button below!
EARN THE GIT BADGE
▶
Good luck to those who attempt the test, and if you pass, congratulations! You are now certified in Git by the BYU Computing Boot Camp.