-
Notifications
You must be signed in to change notification settings - Fork 0
Git Workflow
The gitflow workflow is our preferred workflows, see this excellent article. There is also a git-flow cheatsheet
There are also tools that you can use to help adopt this workflow, on windows there's sourcetree (which I highly recommend) and on linux there's gitflow (use sudo apt-get install git-flow)
To practice your the git flow workflow, feel free to use the practice repository.
The following examples use the commandline (on linux), and the practice repository.
Go to an appropriate directory on your machine. For example /home/user/Projects/, from here on in we will refer to this directory as . If you have ssh-keys setup on github and your local machine, you can use the following to clone the repository (without using any passwords)!
git clone git@github.com:uvcodebase/PracticeRepository.git
If you do not have ssh-keys setup, then you can use this, but you may have to periodically enter your github username and password:
git clone https://github.com/uvcodebase/PracticeRepository.git
This will create a PracticeRepository directory in . Now initialize using git flow:
cd <project-dir>/PracticeRepository
git flow init
Hit enter multiple times to accept the defaults. This will allow us to use the git flow tool to make new features and so forth. This will also put you into the develop branch, where most of the development should happen.
To see what branch you are currently on, and which branches are available, use
git branch
To also see the remote branches use
git branch -a
To switch to a particular branch, use
git checkout <branch name>
where is the name of the branch you want to switch to.
To get the changes that other people have pushed up to github, first fetch the remote changes
git fetch
Now, examine the differences between the remote branch, and the local branch (optional).
git checkout develop
git diff origin/develop
Finally, if you are happy with the modifications, merge the remote changes into your local copy
git checkout develop # Not necessary if you're already in this branch
git merge origin/develop
The git fetch and git merge steps can be combined in the single git pull command, but git pull doesn't allow us to compare the difference between the branches, and is generally discouraged for those who are new to git.
To work on a new feature, use
git flow feature start <my new feature>
where is the name of your new feature. After working on your feature for a while (committing multiple times, potentially merging in changes from develop) you can share your feature with everyone else by using:
git push origin feature/<my new feature>
Go to github and create a pull-request (comparing to the develop branch). After having someone review your code, they will merge in your changes.
Now delete your local branch (optional)
git checkout develop
git branch -D feature/<my new feature>
Note Normally we would finish a feature using git flow feature finish <my new feature>, but we're using github's version of this so that we can have proper code reviews.