Introduction to Git/GitHub
Please Log In for full access to the web site.
Note that this link will take you to an external site (https://petrock.mit.edu) to authenticate, and then you will be redirected back to this page.
Practice and review what you have learned about Git/GitHub using the following problems! This is not a comprehensive list of practice problems, but we hope it is still helpful!
1) Automated Version Control
Just as a reminder, Version Control is useful for things such as having a thorough record of work, providing a convenient way to undo any mistakes, and allowing multiple people to work in parallel.2) Setting Up Git
You should configure your git environment for a specific project or all projects using git config.
git config flag you would use to if you wanted that configuration to be used for all projects (include the --):
3) Creating a Repository
cooking which contains some files and subdirectories breakfast, lunch, and dinner. You want to track files in your lunch subdirectory, what should you do?
4) Tracking Changes
myfile.txt:
5) Exploring History
HEAD~1 refer to ?
123456789:
6) Ignoring Things
If you don't want git to track certain files or directories, you should use a.gitignore file.
Some things to remember:
- Order of rules matters
- The
!character negates a rule - You can use wildcards in your rules
7) Remotes in GitHub
Here is a useful page for creating remotes8) Collaborating
Use git remote -h or git remote --help to find out more about setting up your remote repo.
9) Conflicts
Unfortunately, we can't simulate a merge conflict here on CAT-SOOP, but it is important to not be afraid of them.
While it is best to try to avoid merges by:
- Frequently pulling from upstream
- Using feature branches
- Making smaller commits
- Pushing finished work
- Breaking large files into smaller ones when appropriate
- Discussing project responsibilities with collaborators
- Establishing style rules
Merge conflicts can still happen to the best of us.
Use the following commands as a starting point and explore suggestions on the internet (always make sure you understand the commands you are running before you run them).
git rebase -horgit rebase --helpgit merge -horgit merge --help