How to Allow Developers to Contribute to Your GitHub Project
Now that you have uploaded your project to your company's GitHub account and created two branches (main
and dev
), you need to set up access and define a structured process for developers to contribute. Follow these step-by-step instructions to allow developers to collaborate effectively.
1. Add Developers to the Repository
Step 1: Invite Developers to the Repository
Go to your GitHub repository.
Click on
Settings
>Collaborators and Teams
(if it's a private repository, go toManage Access
).Click Invite a collaborator.
Enter the GitHub usernames of your developers.
Assign them the Write permission (so they can push code).
Click Send Invite.
Developers need to accept the invitation from their GitHub accounts.
2. Developers Set Up the Project Locally
Step 1: Clone the Repository
Each developer should clone the repository to their local machine:
git clone <repository_url>
cd <repository_name>
Step 2: Set Up the Remote Repository
Verify the remote URL:
git remote -v
If needed, add the correct remote:
git remote add origin <repository_url>
Step 3: Switch to the Development Branch
Each developer should work on the dev
branch:
git checkout dev
Ensure they have the latest code:
git pull origin dev
3. Developers Work on Features
Step 1: Create a Feature Branch
Developers should create a new branch for their feature:
g
git checkout -b feature/<feature_name>They should push this branch to GitHub:
git push -u origin feature/<feature_name>
Step 2: Make Changes
Developers write code and make necessary changes.
Add modified files to Git:
git add .
Commit the changes with a meaningful message:
git commit -m "Implemented <feature_name>"
Step 3: Push the Changes
Push the feature branch to GitHub:
git push origin feature/<feature_name>
4. Developers Create a Pull Request (PR)
Step 1: Open a PR on GitHub
Go to the GitHub repository.
Navigate to the
Pull Requests
tab.Click New Pull Request.
Select dev as the base branch and feature/<feature_name> as the compare branch.
Add a title and description for the PR.
Click Create Pull Request.Step 2: Manager Reviews and Merges
You (as the manager) review the PR and provide feedback.
If necessary, request changes. Developers can update their PR by committing and pushing new changes.
Once approved, merge the feature branch into
dev
.After merging, delete the feature branch on GitHub.
5. Keeping the Local Repo Updated
Step 1: Developers Pull Latest Changes
To avoid conflicts, developers should always pull the latest changes from dev
before starting new work:
git checkout dev
git pull origin dev
Step 2: Delete Old Feature Branches Locally (if needed)
git branch -d feature/<feature_name>
Step 3: Fetch and Prune Remote Branches
git fetch --prune
6. Merging Dev into Main for Release
Step 1: Manager Prepares for Deployment
Ensure all PRs have been merged into
dev
.Test the
dev
branch thoroughly.
Step 2: Merge Dev into Main
Switch to the
main
branch:git checkout main
Pull the latest changes:
git pull origin main
Merge
dev
intomain
:git merge dev
Push the updated
main
branch:git push origin main
Step 3: Tag the Release (Optional)
If you want to mark a release version:
git tag -a v1.0 -m "First stable release"
git push origin v1.0
7. Best Practices for Your Team
Branch Naming Convention:
Use prefixes like
feature/
,bugfix/
,hotfix/
.Example:
feature/login-page
,bugfix/api-error
.
Write Meaningful Commit Messages:
git commit -m "Fixed authentication bug"
Pull Latest Changes Regularly:
Before starting any work, always pull the latest updates from
dev
:git pull origin dev
Use PRs for Merging Code:
- Never push directly to
dev
ormain
. Always use pull requests.
- Never push directly to
Code Reviews:
- Ensure every PR is reviewed before merging.
Use .gitignore to Avoid Unwanted Files:
- Make sure unnecessary files (like
node_modules
,.env
) are ignored.
- Make sure unnecessary files (like
Automate Testing (if possible):
- Integrate CI/CD to run tests on PRs.
By following these steps, your developers will be able to collaborate efficiently on the project while maintaining a professional Git workflow. Let me know if you need additional guidance!
Most asked question :
Agar feature branch GitHub ke Pull Request page par show nahi ho rahi, toh uske possible reasons aur solutions kya hain ?
π Check if the Feature Branch Exists on GitHub
Open your GitHub repository.
Click on the "Branches" tab.
Check if your
feature/<feature_name>
branch is listed there.
Agar nahi dikh rahi, toh branch GitHub pe push nahi hui hai.
π Push the Feature Branch to GitHub
Agar branch local system me hai par GitHub pe nahi hai, toh push karne ke liye yeh command run karein:
bashCopyEditgit push -u origin feature/<feature_name>
Isse branch GitHub pe dikhne lagegi.
π Refresh GitHub and Try Again
Agar branch push kar di hai lekin PR me dikh nahi rahi, toh:
Refresh the GitHub page (Ctrl + R / Cmd + R).
Dobara Pull Request create karne ki koshish karein.
π Ensure You're Comparing the Correct Branch
Jab aap PR bana rahi hain:
Base branch:
dev
Compare branch:
feature/<feature_name>
Agar feature branch drop-down me nahi aa rahi, toh dev
branch ko manually select karke dobara try karein.
π Final Check
Agar phir bhi issue aa raha hai, toh yeh command run karein aur output check karein:
bashCopyEditgit branch -r
Agar origin/feature/<feature_name>
list me nahi hai, toh iska matlab hai ki branch GitHub pe push nahi hui. Usko push karein aur phir PR create karein.
Agar ab bhi issue aa raha hai toh batao, hum aur debug karenge! π