Workflow Guide
Visual Representation
Here is a simple visual representation of the Git workflow:
git add–>git commit–>git push
1. Working Directory
The working directory is where you create and modify your files. This is the starting point of the Git workflow.
2. Staging Area
The staging area is where you prepare your files for the next commit. You can think of it as a temporary holding area for your files before they are committed to the local repository.
3. Local Repo
The local repository is where all your commits are stored. This is the central location for all your changes.
4. Remote Repo
The remote repository is a copy of your local repository that is stored on a remote server. This is where you push your changes to share them with others.
Overview of Git Workflow
- Create an issue: You identify a problem or a feature that you want to implement.
- Create a branch: You create a new branch from the main branch (usually called “master”).
- Make changes: You make changes to the code in your branch.
- Commit changes: You commit your changes to the branch.
- Push changes: You push your changes to the remote repository.
- Create a merge request: You create a merge request to merge your branch into the main
- Review and merge: The merge request is reviewed and merged into the main branch.
- Delete branch: The branch is deleted.
- Update main branch: The main branch is updated with the new changes.
- Repeat: The process is repeated for each new feature or bug fix.
Step-by-Step Git Workflow
Here is a step-by-step guide to the Git workflow:
Step 1: Create an Issue
You identify a problem or a feature that you want to implement.
- Go to the GitLab repo
- Click Issues on the side panel
- Click New issue/New item
- Add type of issue, title and description
- Select label: scope and type
- Assign to a team member/self
- Click Create issue
Step 2: Repository Setup
Before you start coding, you need to set up your repository if you haven’t already done so.
Initialize Repo:
git initSet User Info:
git config --global user.name "Your Name"git config --global user.email "your_email@example.com"Clone Repository:
git clone [repository-url]Link Remote Repository:
git remote add origin [repository-url]
Step 3: Create a Branch
Please follow the contributing guidelines for the best practices.
Create Branch:
git branch [branch-name]Switch Branch:
git checkout [branch-name]Create & Switch:
git checkout -b [branch-name]
Step 4: Basic Workflow
Add Changes:
git add .Commit Changes:
git commit -m "type(scope): meaningful message"Push Changes:
git push -u origin [branch-name]Pull Updates:
This will fetch and merge to your local.git pull origin [branch-name]Fetch Updates (without merging):
git fetch origin [branch-name]
Continue Changes
If you want to make future changes to the code, you can use the following commands:
git add .
git commit -m "type(scope): meaningful message"
git push
This command stages all changes, commits them with a meaningful message, and pushes them to the remote repository.
Create Merge Request
To create a merge request:
- Go to the GitLab repo
- Click slide panel Merge requests –> New merge request
- Add a title and description
- Use key word Closes with issue # associated to the issue to automatically resolve the issue.
Rebase
If there are any merge conflicts with your code, please resolve it by following merge-rebase.
Merge Request Approval
- Go to the GitLab repo
- Click Merge requests
- Review the MR
- Click Merge
- Click Confirm merge
- Delete the branch if no longer needed.