3.8 Help! (FAQ)
Link to more “flight rules”, for when you really mess up.
3.8.1 General workflow
- Make sure your
master
branch is up to date- Go to the
master
branch:git checkout master
- Update your
master
branch:git pull origin master
- Go to the
- Create a new branch (give it a useful name):
git checkout -b my_awesome_task
- Give your branch a sensible name about what you are working on
- Don’t just give it your name or pid, nobody knows what you are doing
- Go code and write commits!
git add <my file>
git commit -m 'look at all this cool stuff'
- Push your branch
git push origin my_awesome_task
- Issue a pull request
- Have someone (maintainers) review your code
- Does it follow coding style guides?
- Is the code “good”
- No datasets are checked in
- No loops when an
apply
ormap
function would suffice - There are functions for repetitive code
- Are you checking your work?
- Are the assumptions you are making about data tested in code?
- If you are visually checking/inspecting your data to check your code, is there code written for your visual check?
- etc
- (Maintainers) merge the pull request
- You can also checkoff a box that will also delete the branch on the remote
- Or delete the branch manually under the
branches
view
- Go back to master:
git checkout master
- Pull down your merged code:
git pull origin master
- Delete your branch:
git branch -d my_awesome_task
(note it is a lower case d) - Clean up your branches:
git fetch --prune
3.8.2 Git push rejected (master)
When you run git status
, does it say you’re on master
?
Please see below: “Accidently did work on master
”.
3.8.3 Accidently did work on master
:
- Create a branch where you are now:
git branch BRANCH_NAME
- Find the commit hash of where master is supposed to be
git log --oneline --graph --decorate --all
- Reset master to where you were:
git reset --hard COMMIT_HASH_FOR_MASTER
- make sure you do this on the
master
branch
- make sure you do this on the
- Go to your branch:
git checkout BRANCH_NAME
- Push your branch:
git push origin BRANCH_NAME
- Create and merge the pull/merge request
3.8.4 Get changes from master on your branch
Scenario: You are working on your branch, and the master branch changes (e.g., someone else gets their branch merged into master). The changes in master are also changes you need (e.g., the update to master is a function that you want to use), but you are still working on your branch and not ready to create a pull/merge request and/or merge your changes yet.
- Go to your
master
branch:git checkout master
- Get the new updates from
master
:git pull origin master
- Go back to your branch:
git checkout my_branch
- Rebase your branch against master:
git rebase master
- You may or may not need to solve merge conflicts.
- Force push your branch:
git push -f origin my_branch
3.8.5 Remote server (e.g., GitLab, GitHub, Bitbucket, etc) shows merge conflict
When you attempt to merge a pull/merge request and tells you that the branch cannot be merged becuase of a merge conflict, you need to follow the same steps from “Get changes from master on your branch”. During the rebasing step, you will be fixing the merge conflict(s).
3.8.6 Remove data/files from history
3.8.6.1 BFG repo cleaner
3.8.6.2 Git filter branch
git filter-branch --force --index-filter \
'git rm --cached --ignore-unmatch <PATH_TO_FILE>' \
--prune-empty --tag-name-filter cat -- --all
as a single line: