The basic steps are listed below. They are described in more detail afterwards.
- Update master
- Use a work branch
- Clean up your work before sharing
- Pull request so that people get notified (or merge)
- Clean up your workspace to start again
When doing work, always make sure to update and checkout a new branch. This way, we keep the main branch clean.
git checkout master
git pull origin master
git checkout -b my-work-branch
Before committing to the main branch, clean up your work and make sure it will fit in nicely
git checkout master
git pull origin master
git checkout my-work-branch
git rebase --interactive master
Repeat the rebase until you have achieved work that follows a nice linear history. Make sure that you are only committing the files that you want to be committed, and not some other strange files. You really should be git add
ing the files and not git commit -a
of all the files.
After your work is nice and rebased after the most recent master, pull request the changes so that everyone else who is working gets notified.
git push origin my-work-branch
On github, pull request with master as the main branch and your work branch as the compare branch. If it says that your branch cannot be automatically merged, then you did something wrong. Get rid of your remote branch
git push origin :my-work-branch
and try the clean-up steps again (pull origin master
and rebase --interactive master
).
Alternatively, merge your stuff locally and then push to master
git checkout master
git merge --no-ff my-work-branch
git push origin master
If there are ANY conflicts in the push, reset your master to before the merge commit and pull from the remote again.
Once you automatically merge your work branch, make sure to delete it either from the github interface or locally.
Then, clean up your workspace.
git checkout master
git pull origin master
git branch --delete my-work-branch
git log --decorate --oneline --graph
This will help you figure out what is happening in the git history in order to fix stuff.