https://github.com/k88hudson/git-flight-rules
Stay on the “golden path” and you’ll be safe. Your usual workflow should be something like this:
git pull origin master
#make sure you have the latest version of mastergit checkout -b <newbranchname>
#make a fresh branch off master- Make sure the
.gitignore
is up to date. Always exclude passwords in config files, and any data files, especially large files - they’re hard to remove if you accidentally commit them. - Make changes to your code, then use
git status
to check which files have changed. You may find more files have changed that you expected, for example if black or isort changed the formatting. - Use
git add <filename>
. - Write a useful commit with `git commit -m “”
- Push it up with
git push
- Get a code review
- Once your PR is approved, squash commits and merge in github.
If you committed a file you didn’t want to commit, but don’t want to lose your changes, check the git log
and move the HEAD pointer back a commit or several: reset head --soft or
If you need something from another branch:
Just grab the file:
git checkout <branchname> <filepath>
Or if you want to grab commits, use cherrypick
How to resolve a merge conflict
-
Open the affected file and use your IDE to resolve. This assumes you know which parts to keep. If you don’t:
-
My favorite option is “ours” vs. “theirs” for whole files:
git checkout --ours <filepath>
git checkout --theirs <filepath>
-
Run the tests (this will happen automatically on
git push
once we have everything set up with Jenkins). This is the best way to confirm that you didn’t break anything.