Skip to content

Commit ab1b064

Browse files
authored
folder conflict issue fix (#213)
* test vue * new error added * doc indiv new page added * major update on doc page * husky removed * some minor issue fix * code clean up + code optimize for color * new doc added * new post added + folder rename + minor changes * background color darker * ui + doc page issue fix * try 1 for api issue * folder conflict issue fix
1 parent d8d1b7f commit ab1b064

5 files changed

Lines changed: 232 additions & 6 deletions

File tree

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
Git hooks are powerful scripts that can automate various aspects of your development workflow. They allow you to execute custom scripts before or after important Git events, such as committing, pushing, or merging. This post will introduce you to Git hooks and show you how to leverage them effectively.
2+
3+
## What Are Git Hooks?
4+
5+
Git hooks are scripts that Git executes before or after events such as: commit, push, and receive. They reside in the `.git/hooks` directory of every Git repository and can be written in any scripting language.
6+
7+
## Types of Git Hooks
8+
9+
Git hooks can be categorized into client-side and server-side hooks:
10+
11+
### Client-side Hooks
12+
13+
1. **pre-commit**: Runs before a commit is created
14+
2. **prepare-commit-msg**: Runs before the commit message editor is fired up
15+
3. **commit-msg**: Runs after the commit message is saved
16+
4. **post-commit**: Runs after the commit is created
17+
5. **pre-push**: Runs before a push is executed
18+
19+
### Server-side Hooks
20+
21+
1. **pre-receive**: Runs when the server receives a push
22+
2. **update**: Similar to pre-receive, but runs once for each branch
23+
3. **post-receive**: Runs after a push has been accepted
24+
25+
## Setting Up a Git Hook
26+
27+
1. Navigate to your repository's `.git/hooks` directory.
28+
2. Create a new file with the name of the hook you want to implement (e.g., `pre-commit`).
29+
3. Remove the `.sample` extension if it exists.
30+
4. Make the file executable:
31+
32+
```bash
33+
chmod +x .git/hooks/pre-commit
34+
```
35+
36+
5. Edit the file with your desired script.
37+
38+
## Example: A Simple pre-commit Hook
39+
40+
Here's a simple pre-commit hook that checks for debugging statements:
41+
42+
```bash
43+
#!/bin/sh
44+
45+
if git diff --cached | grep -E '(console.log|debugger)' > /dev/null; then
46+
echo "Error: Debugging statements detected. Please remove them before committing."
47+
exit 1
48+
fi
49+
```
50+
51+
This script checks for `console.log` or `debugger` statements in your staged changes and prevents the commit if any are found.
52+
53+
## Best Practices for Using Git Hooks
54+
55+
1. **Keep hooks simple**: Complex hooks can slow down Git operations.
56+
2. **Use hooks consistently**: Ensure all team members use the same hooks.
57+
3. **Version control your hooks**: Store hooks in your repository and symlink them.
58+
4. **Make hooks configurable**: Allow developers to bypass hooks when necessary.
59+
5. **Document your hooks**: Ensure team members understand what each hook does.
60+
61+
## Sharing Hooks with Your Team
62+
63+
To share hooks with your team:
64+
65+
1. Create a `hooks` directory in your repository.
66+
2. Add your hook scripts to this directory.
67+
3. Create a setup script that symlinks these hooks to `.git/hooks`.
68+
4. Add instructions for running the setup script to your README.
69+
70+
## Advanced Git Hook Usage
71+
72+
### Linting
73+
74+
Use a pre-commit hook to run linters:
75+
76+
```bash
77+
#!/bin/sh
78+
79+
if ! npm run lint; then
80+
echo "Linting failed. Please fix errors before committing."
81+
exit 1
82+
fi
83+
```
84+
85+
### Automatic Formatting
86+
87+
Use a pre-commit hook to automatically format code:
88+
89+
```bash
90+
#!/bin/sh
91+
92+
if ! npm run format; then
93+
echo "Formatting failed. Please run formatting manually and try again."
94+
exit 1
95+
fi
96+
```
97+
98+
### Preventing Commits to Specific Branches
99+
100+
Use a pre-commit hook to prevent direct commits to protected branches:
101+
102+
```bash
103+
#!/bin/sh
104+
105+
branch="$(git rev-parse --abbrev-ref HEAD)"
106+
107+
if [ "$branch" = "main" ]; then
108+
echo "You can't commit directly to main branch"
109+
exit 1
110+
fi
111+
```
112+
113+
## Conclusion
114+
115+
Git hooks are a powerful tool for automating and enforcing development workflows. By implementing appropriate hooks, you can improve code quality, enforce coding standards, and streamline your development process.
116+
117+
Remember, while hooks are powerful, they should be used judiciously. Overly restrictive hooks can hinder productivity, so strike a balance between automation and flexibility.
118+
119+
Happy coding, and may your Git hooks serve you well!
120+
121+
> Written by **Sakib Ahmed** | [GitHub](https://github.com/devvsakib)

public/assets/posts/index.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
[
2+
{
3+
"title": "pull_request_tutorial_for_beginners"
4+
},
5+
{
6+
"title": "mastering_git_branching_strategies"
7+
},
8+
{
9+
"title": "git_hooks_automating_your_workflow"
10+
}
11+
]
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
Git branching is a powerful feature that allows developers to work on different parts of a project simultaneously. However, without a clear strategy, it can lead to confusion and conflicts. In this post, we'll explore some popular Git branching strategies to help you collaborate more effectively.
2+
3+
## Why Branching Strategies Matter
4+
5+
Before diving into specific strategies, let's understand why they're important:
6+
7+
1. **Organization**: They keep your repository organized and easy to navigate.
8+
2. **Collaboration**: They facilitate smooth teamwork by clearly defining workflows.
9+
3. **Stability**: They help maintain a stable main branch while allowing experimentation.
10+
4. **Release Management**: They simplify the process of preparing and deploying releases.
11+
12+
## Popular Branching Strategies
13+
14+
### 1. GitFlow
15+
16+
GitFlow is one of the most well-known branching models. It uses two main branches:
17+
18+
- `main`: Always reflects the production-ready state.
19+
- `develop`: Serves as an integration branch for features.
20+
21+
Additional supporting branches include:
22+
23+
- Feature branches
24+
- Release branches
25+
- Hotfix branches
26+
27+
#### Pros:
28+
- Clear separation of concerns
29+
- Suitable for projects with scheduled releases
30+
31+
#### Cons:
32+
- Can be complex for smaller projects
33+
- May lead to long-lived feature branches
34+
35+
### 2. GitHub Flow
36+
37+
GitHub Flow is a simpler alternative to GitFlow. It uses a single main branch and feature branches:
38+
39+
1. Create a branch from `main`
40+
2. Add commits
41+
3. Open a pull request
42+
4. Discuss and review
43+
5. Deploy for testing
44+
6. Merge to `main`
45+
46+
#### Pros:
47+
- Simple and easy to understand
48+
- Encourages continuous delivery
49+
50+
#### Cons:
51+
- Less suitable for projects with multiple versions in production
52+
53+
### 3. Trunk-Based Development
54+
55+
This strategy involves keeping branches short-lived and merging frequently to a single "trunk" branch (usually `main`):
56+
57+
- Developers create short-lived feature branches
58+
- Branches are merged to `main` at least once a day
59+
- `main` is always in a releasable state
60+
61+
#### Pros:
62+
- Supports continuous integration effectively
63+
- Reduces merge conflicts
64+
65+
#### Cons:
66+
- Requires a robust testing and CI/CD pipeline
67+
- May be challenging for less experienced teams
68+
69+
## Choosing the Right Strategy
70+
71+
The best branching strategy depends on various factors:
72+
73+
- Team size and experience
74+
- Project complexity
75+
- Release frequency
76+
- Deployment process
77+
78+
Consider these factors when selecting a strategy, and don't be afraid to adapt it to your team's needs.
79+
80+
## Implementing Your Chosen Strategy
81+
82+
Once you've chosen a strategy:
83+
84+
1. Document it clearly
85+
2. Ensure all team members understand the workflow
86+
3. Use tools like branch protection rules to enforce the strategy
87+
4. Regularly review and refine your approach
88+
89+
## Conclusion
90+
91+
A well-implemented Git branching strategy can significantly improve your team's productivity and code quality. Whether you choose GitFlow, GitHub Flow, Trunk-Based Development, or a custom approach, the key is consistency and clear communication within your team.
92+
93+
Remember, the best strategy is one that your team can follow effectively. Start with a basic approach and evolve it as your project and team grow.
94+
95+
Happy branching!
96+
97+
> Written by **Sakib Ahmed** | [GitHub](https://github.com/devvsakib)

public/posts/pull_request_tutorial_for_beginners.md renamed to public/assets/posts/pull_request_tutorial_for_beginners.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,4 +119,6 @@ You may also delete the branch from your fork on GitHub.
119119

120120
Congratulations! You've successfully created and merged a pull request. This process helps maintain code quality and encourages collaboration among developers.
121121

122-
This tutorial covers the basics of creating a pull request and includes best practices to help beginners understand the process.
122+
This tutorial covers the basics of creating a pull request and includes best practices to help beginners understand the process.
123+
124+
> Written by **Sakib Ahmed** | [GitHub](https://github.com/devvsakib)

public/posts/index.json

Lines changed: 0 additions & 5 deletions
This file was deleted.

0 commit comments

Comments
 (0)