Spaces:
Paused
Paused
File size: 4,875 Bytes
22a005d | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 | # Git Workflow: Branch, Commit, Push, and Pull Request
This document outlines the standard workflow for creating a branch, committing changes, pushing to remote, and creating a pull request.
## Prerequisites
- Git installed and configured
- GitHub CLI (`gh`) installed (optional, but recommended for PR creation)
- Access to the repository
- Authentication configured (SSH keys or GitHub CLI authentication)
## Step-by-Step Workflow
### 1. Check Current Status
First, check what changes exist in your working directory:
```bash
git status
```
This shows:
- Modified files
- Deleted files
- Untracked files
- Current branch
### 2. Create a New Branch
Create and switch to a new branch for your changes:
```bash
git checkout -b <branch-name>
```
**Branch naming conventions:**
- `feature/` - for new features
- `fix/` or `bugfix/` - for bug fixes
- `refactor/` - for code refactoring
- `docs/` - for documentation changes
- `chore/` - for maintenance tasks
**Example:**
```bash
git checkout -b refactor/monorepo-restructure
```
### 3. Stage Changes
Stage all changes (including deletions and new files):
```bash
git add -A
```
Or stage specific files:
```bash
git add <file1> <file2>
```
### 4. Commit Changes
Create a commit with a descriptive message:
```bash
git commit -m "type: descriptive commit message"
```
**Commit message conventions:**
- Use conventional commits format: `type: description`
- Types: `feat`, `fix`, `refactor`, `docs`, `chore`, `test`, `style`
- Keep messages concise but descriptive
**Example:**
```bash
git commit -m "refactor: restructure project to monorepo with apps directory"
```
### 5. Push Branch to Remote
Push your branch to the remote repository:
```bash
git push -u origin <branch-name>
```
The `-u` flag sets up tracking so future pushes can use `git push` without specifying the branch.
**Example:**
```bash
git push -u origin refactor/monorepo-restructure
```
### 6. Create Pull Request
#### Option A: Using GitHub CLI (Recommended)
If you have GitHub CLI installed:
```bash
gh pr create --title "Your PR Title" --body "Description of changes"
```
To open in browser for review before creating:
```bash
gh pr create --title "Your PR Title" --body "Description" --web
```
#### Option B: Using GitHub Web Interface
After pushing, GitHub will provide a URL in the terminal output:
```
remote: Create a pull request for '<branch-name>' on GitHub by visiting:
remote: https://github.com/<org>/<repo>/pull/new/<branch-name>
```
Visit that URL to create the PR through the web interface.
#### Option C: Manual PR Creation
1. Go to your repository on GitHub
2. Click "Pull requests" tab
3. Click "New pull request"
4. Select your branch as the source
5. Select the target branch (usually `main` or `master`)
6. Fill in title and description
7. Click "Create pull request"
## Complete Example Workflow
```bash
# 1. Check status
git status
# 2. Create branch
git checkout -b feature/add-new-component
# 3. Make your changes (edit files, etc.)
# 4. Stage changes
git add -A
# 5. Commit
git commit -m "feat: add new user dashboard component"
# 6. Push
git push -u origin feature/add-new-component
# 7. Create PR
gh pr create --title "feat: add new user dashboard component" --body "Implements new dashboard component with user statistics and activity feed."
```
## Handling Additional Changes
If you need to make more changes after pushing:
```bash
# Make your changes
git add -A
git commit -m "fix: address review feedback"
git push
```
The PR will automatically update with the new commits.
## Troubleshooting
### Branch already exists
```bash
git checkout <existing-branch-name>
```
### Need to update from main before creating PR
```bash
git checkout main
git pull origin main
git checkout <your-branch>
git merge main
# Resolve conflicts if any
git push
```
### PR creation fails
- Ensure branch is pushed: `git push -u origin <branch-name>`
- Check GitHub CLI authentication: `gh auth status`
- Verify repository access permissions
- Try creating PR via web interface instead
## Best Practices
1. **Keep branches focused**: One branch = one feature/fix
2. **Write clear commit messages**: Help reviewers understand changes
3. **Keep PRs small**: Easier to review and merge
4. **Update before creating PR**: Merge latest `main` into your branch
5. **Add tests**: Include tests for new features
6. **Update documentation**: Keep docs in sync with code changes
7. **Request reviews**: Tag relevant team members for review
## Quick Reference Commands
```bash
# Status check
git status
# Create branch
git checkout -b <branch-name>
# Stage all changes
git add -A
# Commit
git commit -m "type: message"
# Push
git push -u origin <branch-name>
# Create PR (GitHub CLI)
gh pr create --title "Title" --body "Description"
# View PR
gh pr view
# List PRs
gh pr list
```
|