-
Notifications
You must be signed in to change notification settings - Fork 0
Team Tips & Tricks
Our project has a lot of fetching. CSRF protection with fetch is moderately annoying, so we built a utility wrapper called fetchWithToken
that hides some of the syntax and makes it cleaner. To use it:
- At the top of your file import the
/public/javascripts/utils.js
file. If you are in the/public/javascripts/
folder the syntax looks like this
import { fetchWithToken } from "/utils.js"
Note that you cannot use common JS module syntax in these files ("require") and the .js
extension IS required. To use fetchWithToken you just pass in the URI, the method, and the JSON stringified body of your fetch request. The wrapper will construct all the headers and parameter objects for you and you canawait
it or use it in a Promise chain just like you would use fetch
.
- Create a new branch for every feature by
git branch my_feature_here
orgit checkout -b my_feature_here
. The latter is a shortcut to create the branch and switch at the same time. Where possible, you should create your branch on a freshly pulled main - Complete your feature / fix, commit your changes with
git commit -m "this message should be useful and describe what you did
git checkout main
git pull main
- Switch back to your feature branch with
git checkout my_feature_here
git rebase main
- Resolve any merge conflicts. Ask for help if you need it! This step is important! When you're done,
git add
the changes andgit rebase --continue
- Push your code and there should be no merge conflicts with the remote ** main**
This flow is very important because it helps keep a clean history and reduces the chance of accidentally clobbering important changes. Please do it every time!
It happens! Don't panic! If it was just one commit:
-
git branch a_new_branch_name_here
. Note we did NOT checkout the branch. Don't use the shortcut. -
git reset HEAD~1
This will move main back before your stray commit. -
git checkout a_new_branch_name_here
Checkout the new branch you made. Your commit is there and you can continue working/push your work.
If you made multiple commits you will need to add an extra step between 1 and 2 where you use git log
to see how many commits back you need to rewind.