GIT Workflow Guide
This document provides detailed instructions and commands to handle various Git operations
based on our branching strategy. Follow these steps and commands carefully to maintain
consistency and efficiency within the team.
Branching Strategy
Develop Branch: This is the test environment where new tasks are merged after review.
•
Main Branch: This is the production environment and should only contain stable, tested
•
code.
Workflow Overview
1. Create a new branch from develop for each task.
2. Make your changes and push them to a remote task branch.
3. Raise a Pull Request (PR) to merge your task branch into develop .
4. Keep your task branch updated by pulling with rebase from develop .
5. After the PR is merged, delete both the local and remote task branches.
Common Scenarios and Commands
1. Setting Up Your Local Repository
Ensure you have the latest state of the remote repository:
# Clone the repository (if not already cloned)
git clone <repository-url>
# Navigate to the repository directory
cd <repository-directory>
# Fetch all branches
git fetch --all
2. Starting a New Task
Create a task branch from develop :
# Create and switch to a new task branch
git checkout -b <local-task-branch-name> -t origin/develop
3. Making Changes and Pushing to Remote - 1st Task Commit
After making changes to the code:
# Check the status of your changes
git status
# Stage your changes
git add .
# Commit your changes (use the template below)
git commit
# Push your task branch to the remote repository
git push origin <local-task-branch-name>:<remote-task-branch-name>
Commit Message Template
[JIRA Id] Task Summary
Task: <Details about the Task>
Solution: <Changes made and the approach taken for the task>
4. Raising a Pull Request
1. Navigate to the repository on GitHub.
2. Locate your task branch.
3. Click New Pull Request and select develop as the base branch.
4. Add a title and description for your pull request and submit it.
5. Updating Task Branch to Pull all Changes from Develop branch
Rebase your branch with the latest changes from develop :
# Ensure you're on your task branch and there are no local changes
git checkout <local-task-branch-name>
# Pull with rebase
git pull --rebase origin develop
# Resolve any conflicts if prompted (edit files, then run the following):
git add .
git rebase --continue
# Repeat above steps as long as the rebase is not complete
# Push the updated task branch
git push --force-with-lease origin <local-task-branch-name>:<remote-task-branch-name>
6. Additional commits for a Task
Make all your changes and commit them
# Check the status of your changes
git status
# Stage your changes
git add .
# Commit your changes. We will be fixing up this commit and hence it is fine to not follow the template.
git commit -m "Additional Changes"
To fix up commits so that all changes for the task are combined into a single commit:
# Interactive rebase to fix up commits
git rebase -i HEAD~<number-of-commits>
1. Replace pick with fixup (or f ) for all but the first commit in the list.
2. Save and close the editor.
If there are no conflicts:
# Force-push the updated commit
git push --force-with-lease origin <local-task-branch-name>:<remote-task-branch-name>
If conflicts arise during the rebase:
# Resolve the conflicts manually.
# Stage the resolved files
git add .
# Continue the rebase
git rebase --continue
To abort the rebase if needed:
git rebase --abort/
7. Merging a Pull Request
1. Once your PR is approved, merge it into develop via the GitHub interface.
2. Ensure all automated checks pass before merging.
8. Cleaning Up Branches
After your PR is merged you must delete the unwanted branches. Be sure that the changes were
merged before deleting.
# Delete the remote task branch
git push origin --delete <remote-task-branch-name>
# Delete the local task branch
git branch -d <local-task-branch-name>