ENGR 100 Git Tips
This is a set of tips to make using Git as easy and painless as possible. You
are most than welcome to use advanced features of Git, but if you are looking
to get away with the bare minimum then you may find this helpful.
The Golden Rule
Never delete history. This is the easiest way to accidentally delete part or
all of your work. We have disabled this feature on GitHub to try to prevent
the issue, but we'd rather you not try to remove history as this frequently
results in bad things. Removing history includes:
- Using the -f or --force option for anything, mainly
git push.
- Using git rebase, or git replace
- Using the --amend option for git commit after the commit
has already been pushed.
- Any other command that looks like it changes previous commits.
If you are trying to correct an accidental commit, instead use git
revert. This will create a new commit that reverts your changes to a
previous commit without running the risk of deleting history. For example, if
you wish to create a new commit that is identical to 1 commit before the
current commit, use git revert HEAD~1
Tips
- Be very careful when using the --hard option for anything. This
will typically permanently remove any uncommitted changes to your local copy.
If you are going to use this option, we strongly recommend making a quick
backup of your working copy, such as copying all files to a different directory
or using the git stash command.
- Be careful when solving merge conflicts. Git inserts extra text to denote
differences between versions of a file, and leaving this text in will almost
always break code and cause confusion. You can also end up merging files that
you did not want to merge.
- Be careful with branches, if you decide to use them. Merging branches can
be problematic.
- When in doubt, ask an instructor. We are all fairly well versed in
Git and can help you out in almost any situation. Asking before doing is always
best, because it will require less work than if something is done incorrectly.
Plus, we may have a nice trick or two to show you!