By Ira Herman
Use this workflow when working with teams to take advantage of Pull Requests and keep the master branch clean.
git checkout -b ira
In the future, you don't need the -b
for this git repo, that is just to create a NEW branch if it doesn't exist in this repo.
git checkout master
Switches to the master branchgit checkout ira
Switches to the ira branch- etc
Make updates on your branch and some git commits. When you're ready to merge into the master, do this:
git push origin ira
In github's web interface, Create a PR (Pull Request).
NOTE: If you don't know how to do this, google create pull request github
Anyone on your team can create and submit pull requests, but be sure the Release Manager (Repo master) manages and merges the PR's. In the case of any conflicts that need to be merged via github's PR web interface, the Release Manager and anyone involved in the code conflicts work together to help merge changes and closes pull request.
git checkout master
git pull
(pulls down the latest master from github, with all the changes from merged in PR's included)- Then each team member merges the updated master code into their named branch to get the latest updates.
-
Method 1:
- Make sure you have your named branch checked out:
git checkout ira
git merge master
to merge all the latest master changes into your branch
- Make sure you have your named branch checked out:
-
Method 2:
- Use this method if you are using a git visualizer and want the branch history to look cleaner (optional):
git checkout master
git branch -D ira
(deletes your branch locally)git checkout -b ira
(recreates your branch as a brand new branch using the updated master as a base)
-
That's the main workflow for teams.
If you’re not seeing the latest master changes in your pull request, you might need to do a local merge then push your branch back up to github again. Then create a new pull request and you’ll see the correct baseline and changes.
git checkout master
git pull
git checkout ira
(or whatever your branch name is 😄)
git merge master
You’ll get an error about merge conflicts. Read it to see which files have conflicts you need to resolve.
Let’s say you get a conflict in App.js
.
- Open
App.js
in your code editor.
Any spot where there’s a conflict, you are going to see something like this:
<<<<<<<
One person’s code
=======
Another person’s code
>>>>>>>
You’ll need to delete all the <<<<
’s, =====
’s, and >>>>
’s and replace that section with just the good code that should be there. Sometimes you need to get creative and merge both sets of code together — but be sure to avoid duplication or unclosed parenthesis, etc.
Once you’ve removed and replaced all the conflicts in your affected file(s), do a
git add -A
git commit -m “resolved merge conflicts”
git push ira
(replace ira with your branch name)
Congratulations! You have manually merged your code based on the latest master!
Now create a pull request and it should do what you expect it to :)