How to Allow Developers to Contribute to Your GitHub Project

Β·

5 min read

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

  1. Go to your GitHub repository.

  2. Click on Settings > Collaborators and Teams (if it's a private repository, go to Manage Access).

  3. Click Invite a collaborator.

  4. Enter the GitHub usernames of your developers.

  5. Assign them the Write permission (so they can push code).

  6. Click Send Invite.

  7. 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

  1. Developers should create a new branch for their feature:

     g
    
  2. git checkout -b feature/<feature_name>They should push this branch to GitHub:

     git push -u origin feature/<feature_name>
    

Step 2: Make Changes

  1. Developers write code and make necessary changes.

  2. Add modified files to Git:

     git add .
    
  3. Commit the changes with a meaningful message:

     git commit -m "Implemented <feature_name>"
    

Step 3: Push the Changes

  1. 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

  1. Go to the GitHub repository.

  2. Navigate to the Pull Requests tab.

  3. Click New Pull Request.

  4. Select dev as the base branch and feature/<feature_name> as the compare branch.

  5. Add a title and description for the PR.

    Click Create Pull Request.Step 2: Manager Reviews and Merges

  6. You (as the manager) review the PR and provide feedback.

  7. If necessary, request changes. Developers can update their PR by committing and pushing new changes.

  8. Once approved, merge the feature branch into dev.

  9. 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

  1. Ensure all PRs have been merged into dev.

  2. Test the dev branch thoroughly.

Step 2: Merge Dev into Main

  1. Switch to the main branch:

     git checkout main
    
  2. Pull the latest changes:

     git pull origin main
    
  3. Merge dev into main:

     git merge dev
    
  4. 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

  1. Branch Naming Convention:

    • Use prefixes like feature/, bugfix/, hotfix/.

    • Example: feature/login-page, bugfix/api-error.

  2. Write Meaningful Commit Messages:

     git commit -m "Fixed authentication bug"
    
  3. Pull Latest Changes Regularly:

    • Before starting any work, always pull the latest updates from dev:

        git pull origin dev
      
  4. Use PRs for Merging Code:

    • Never push directly to dev or main. Always use pull requests.
  5. Code Reviews:

    • Ensure every PR is reviewed before merging.
  6. Use .gitignore to Avoid Unwanted Files:

    • Make sure unnecessary files (like node_modules, .env) are ignored.
  7. 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

  1. Open your GitHub repository.

  2. Click on the "Branches" tab.

  3. 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:

  1. Refresh the GitHub page (Ctrl + R / Cmd + R).

  2. Dobara Pull Request create karne ki koshish karein.

πŸ”€ Ensure You're Comparing the Correct Branch

Jab aap PR bana rahi hain:

  1. Base branch: dev

  2. 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! πŸš€

Β