3.8 Help! (FAQ)

Link to more “flight rules”, for when you really mess up.

3.8.1 General workflow

  1. Make sure your master branch is up to date
    1. Go to the master branch: git checkout master
    2. Update your master branch: git pull origin master
  2. 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
  3. Go code and write commits!
    1. git add <my file>
    2. git commit -m 'look at all this cool stuff'
  4. Push your branch git push origin my_awesome_task
  5. Issue a pull request
  6. 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 or map 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
  7. (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
  8. Go back to master: git checkout master
  9. Pull down your merged code: git pull origin master
  10. Delete your branch: git branch -d my_awesome_task (note it is a lower case d)
  11. 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:

  1. Create a branch where you are now: git branch BRANCH_NAME
  2. Find the commit hash of where master is supposed to be
    • git log --oneline --graph --decorate --all
  3. Reset master to where you were: git reset --hard COMMIT_HASH_FOR_MASTER
    • make sure you do this on the master branch
  4. Go to your branch: git checkout BRANCH_NAME
  5. Push your branch: git push origin BRANCH_NAME
  6. 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.

  1. Go to your master branch: git checkout master
  2. Get the new updates from master: git pull origin master
  3. Go back to your branch: git checkout my_branch
  4. Rebase your branch against master: git rebase master
    • You may or may not need to solve merge conflicts.
  5. 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.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:

git filter-branch --force --index-filter 'git rm --cached --ignore-unmatch <PATH_TO_FILE>' --prune-empty --tag-name-filter cat -- --all