Development Workflow with Git and Github - TeamCrown/First-project GitHub Wiki
TeamCrown Development Workflow with Git and Github
Git provides a tremendous amount of freedom and little guidance, so teams often have to define their own best practices. This document defines the workflow we use in TeamCrown projects.
We highly recommend using Git CLI, since it is consistent across platforms.
If you think more than one person is needed to work on a single branch, consider breaking the work into smaller units.
Setup
-
Install Git
-
Set your username and email for Git:
git config --global user.name "Your name here"
git config --global user.email "[email protected]"
-
Follow the instructions here for generating a new SSH key and adding it to the ssh-agent. Do not forget to add your SSH key to your GitHub account.
-
Check if your setup is complete:
ssh -T [email protected]
You should see a message like
Hi YOUR_USERNAME! You've successfully authenticated...
-
Clone the repository:
git clone https://github.com/TeamCrown/First-project.git
Do NOT create your own fork. It is not the workflow we will use.
-
Enter to the project folder:
cd First-project
-
Check if everything is setup correctly:
git remote --verbose
The output should look like
origin https://github.com/TeamCrown/First-project.git (fetch)
origin https://github.com/TeamCrown/First-project.git (push)
The Workflow
The code changes you commit should tie back to a task on Trello. If that is not the case, please create a task.
master
represents the official history and should ALWAYS be deployable. For each feature, a developer creates a new branch. For clarity, make sure to add your name as prefix and use descriptive names like minasie.github-workflow
for your branches.
To create a branch:
- Checkout to master:
git checkout master
- Pull latest changes:
git pull
- Create a new branch and switch to it:
git checkout -b your-name.new-feature-branch
Branch management
While working on a new feature branch, it is a good idea to commit often. This allows us to move forward without fear since if something goes wrong you can revert back easily without losing too much work. Keep in mind that it's better to divide the work into small chunks so that each commit is easily digestible by every developer.
Commit your code
-
Get the status:
git status
This command will give you a list of all the updated, added and deleted files.
-
Files can be added individually or all at once:
git add FILE
orgit add -A
-
Now we are ready to create a commit with changes:
git commit
This will open selected text editor two write a commit message.
If the change is not complicated:
* `[CHANGE_TYPE] + one line commit message`
If the change is complicated:
* `[CHANGE_TYPE] + one line commit message + an empty line + detailed explanation lines`
A good commit message would look like:
* `[doc] Add Github workflow`
As seen above, we prefer to use an imperative form for simplicity. The change type is in brackets. Some other examples of change type could be your team's name or specific technology like [mobile], [backend], [web], [db]
etc.
Please be consistent and follow the conventions.
Rebase and (squash if needed) your branch
Squashing will condense commits into a new commit. This is important to keep the commit history clean.
git rebase -i master
This will open your default editor and present you the list of commits to be rebased. Each commit in your branch is listed at the top of the file. You should keep the top/oldest commit and squash all of the other commits into it. To do this, simply change pick
to squash
for all the commits except the top one.
As rebase processes your commits, it may run into a merge conflict (for example, if you and upstream changed the same part of a file). If this happens, rebase will pause and wait for you to manually resolve the conflict. To do this, simply run git status to find out which file(s) have conflicts and then go into each one and resolve them.
-
Once you’re done, first run
git add -A
This will stage each file.
-
Continue the rebase with:
git rebase --continue
-
To push the new feature branch to the remote repo, simply do the following:
git push -u origin your-name.new-feature-branch
At this point, you are ready to create a Pull Request
for the new feature.
Create a Pull Request
- Click on
New pull request
on the project site. - Select
master
as the base branch. - Select
your-name.new-feature-branch
as the compare branch. - Add
one or two
reviewers.
The reviewers should review the PR in 24 hours and leave their comments. Note that we do not allow any direct pushes to masters without creating a PR and getting approval from reviewers. Once you addressed all the comments on your PR, and rebase your fix comments with the rebase workflow above, it's time to push your changes.
-
Rebase on master again to be up-to-date:
git rebase -i master
This time you might not have to squash anything.
-
Push on your feature branch so that your PR will get closed automatically. You might have to force-push, in that case, use the
-f
flag.git push
orgit push -f
-
Checkout to master:
git checkout master
-
Retrieve the changes from your feature branch to master:
git rebase your-name.new-feature-branch
-
Push to remote master:
git push
Congratulations! You are ready to contribute TeamCrown!