- Create a fork and working copy on local machine.
- Clone the fork
git clone [ssh address to repo]* Move into the git directorycd [git project directory]* Add the upstream linkgit remote add upstream [the read-only git address to repo that was forked from]
- Update your master branch fork with upstream changes.
git pull git pull origin master git push
- Create a branch to work on and switch to that branch
git checkout -b [branch name]
- Make changes to files and commit to this branch.
- To check for conflicts
- First bring your master branch up to date with these commands.
git checkout master git pull git pull upstream master git push
- Then merge the changes.
git checkout [branch name] git merge master
- First bring your master branch up to date with these commands.
###When your changes are ready###
- Update your master branch, and rebase your topic branch.
git checkout [branch name] git pull upstream master git -i rebase master* At this point you can clean up your commits by squashing, editing or deleting them. * One reason you might want to squash commits is if there were many small commits that accomplish one task this way the history is easier to read for the person who is to review your code.
- If there are conflicts, fix the conflicts and git add them before --continue.
First resolve conflicts git add [fileName with conflicts] git rebase --continue
- When changes are complete then merge to master and push.
git checkout master git merge [branch name] git push
- Finally delete your working branch
git branch -d [branch name]
- Some people like to work from branches that are public. If you work from public branches then rebasing is not advised (since your history is public rebasing can break someone else's project). Instead of rebasing just preform the merge into your master branch.
- Working with remote branches.
- To make a remote branch
git checkout -b dev_event_cbs master git push origin -u dev_event_cbs* Then to delete the remote branch (after merging, or after the pull request has been accepted)git checkout master git pull upstream master git push git branch -D dev_event_cbs git push origin --delete dev_event_cbs
Git reference
Pro git book - Professional Version Control
Avoiding Git Disasters: A Gory Story
A Rebase Workflow for Git
A Git Workflow for Agile Teams
A rant from Linus