centralized workflow + feature branching should be used for a small dev team
- Team members should be the contributors with push permission to the centralized repo
- Keep the master branch as a stable release branch
- Each team member will create a new feature branch (e.g. feature-XXX)
- Sync with the master branch and resolve conflicts
- Commit your changes and publish to the feature branch
- Send a pull request to the master branch
- Code review and merge OR reject the changes
Further references about different workflows:
Clone the whole repository for the first time
git clone [Repo URL]
Checkout a remote branch and create a local branch. Local and remote branch can have different name.
git checkout -b [branch name] origin/[branch name]
Create a new branch
git checkout -b [branch-name]
Query the current branches
git branch
Switch to another branch
git checkout [branch-name]
git add . # stage files (new, modified, deleted, equivalent to ``git add -A``)
git commit -m "[Comment]" # write a reasonable commit log
git checkout master # switch to the local master
git pull # pull from remote master branch
git checkout [branch name] # switch to the feature branch
git merge master # merge diff from master
Please resolve conflicts and errors before pushing to the remote repo
If it is the first time to push from local to remote, additional parameters are needed:
git checkout [branch name] # switch to the feature branch
git push --set-upstream origin [branch name] # create a new feature branch in the upstream and push
Otherwise:
git checkout [branch name] # switch to the feature branch
git push # push from local to remote feature branch
- Switch to the GitHub web interface
- Select the
branch name
you would like to merge to master - Click
New pull request
button - Type in the pull request title and comments
- Review commit log messages and file changes
- Code review. If needed, the feature branch maintainer should make changes and commit to the feature branch. The pull request will be automatically updated.
- The master branch maintainer approves/rejects the merge, or keep the discussing the issues via the pull request
Once the branch is merged, we may delete the feature branch:
Delete a local branch:
git branch -d [branch name]
Delete a remote branch
git push origin --delete [branch name]
Alternatively, you can use a web interface to delete a remote branch
git log
The commit ids can also be found via the web interface at GitHub
git checkout [commit id] # temporary detach and view
git checkout [branch name] # switch to a branch, the temporary view is removed
git checkout -b [new branch name] [commit id] # create a new branch from an old commit
Other advanced operations: StackOverflow: How to revert Git repository to a previous commit?
If you need to remove a file from both git repo and local filesystem:
git rm [filename]
If you only want to remove a file from git repo (and keep the local copy):
git rm --cached [filename]
git push
git branch -m <oldname> <newname>