Sanyukta Suman Logo Sanyukta Suman
Blog Post Thumbnail
Image credit: Source

Work on external Github account with your personal Github account

Published on August 13, 2024

To collaborate on an external GitHub repository using your own account, you'll need to follow a process that involves creating a repository, forking it, and then using a pull request to merge your changes. This is a common workflow for contributing to open-source projects or collaborating with others without direct write access to the main repository.

Step 1: Create the Repository (External Account)

First, you'll need to create the repository on the external GitHub account.

  1. Log in to the external account and click the '+' icon in the top right corner, then select 'New repository'.
  2. Give the repository a name (e.g., 'Project_Repo').
  3. Choose the visibility of the repository:
    • Public: Anyone can see this repository. You choose who can commit to it. This is ideal for open-source projects.
    • Private: You choose who can see and commit to this repository. This is best for internal, private projects.
  4. Optionally, initialize the repository with a README file, which provides a description of the project.
  5. Click 'Create repository'.

Now, you have a repository on the external account.

Step 2: Grant Permissions (External Account)

If the repository is private, you need to give your personal account access.

  1. On the external account, navigate to the new repository.
  2. Go to the 'Settings' tab.
  3. In the left-hand menu, select 'Collaborators and teams'.
  4. Click 'Add collaborator' and search for your personal GitHub account username.
  5. Select your personal account and click 'Add [your_username] to this repository'. GitHub will send an invitation to your personal account.

Step 3: Fork the Repository (Your Account)

Now, you'll work from your personal GitHub account to create a copy of the repository.

  1. Log into your personal GitHub account.
  2. Go to the external repository's page (the one you just created).
  3. In the top-right corner, click the 'Fork' button. This creates a copy of the repository under your personal GitHub account.
  4. A new page will appear, confirming the creation of the fork. This is now your working copy, and you can make changes to it without affecting the original repository.

Step 4: Clone and Work on Your Local Machine

Next, you'll bring the code from your forked repository to your computer.

  1. On your personal GitHub account, go to the forked repository.
  2. Click the green '<> Code' button and copy the URL.
  3. Open your terminal or command prompt on your computer.
  4. Use the git clone command to download the repository:

    git clone <pasted_url>
  5. Change into the new directory:

    cd <repository_name>
  6. You can now make changes to the files using your preferred code editor.

Step 5: Commit and Push Changes

After making changes, you need to save them and upload them to your forked repository.

  1. In your terminal, add the changes you want to commit:

    git add .
  2. Commit the changes with a descriptive message:

    git commit -m "Your descriptive commit message"
  3. Push the changes to your forked repository on GitHub:

    git push origin main

    (Note: The default branch may be main or master. Check your repository for the correct branch name).

Step 6: Create a Pull Request

This is the final step where you propose your changes to be merged into the original repository.

  1. Go to your forked repository on GitHub.
  2. You should see a banner at the top that says something like "This branch is 1 commit ahead of [external_account]:[branch]". Click the 'Contribute' button or 'New pull request'.
  3. Review your changes and provide a clear title and description for your pull request. This helps the maintainer of the original repository understand what you did.
  4. Click 'Create pull request'.

The maintainer of the external repository will now be able to review your changes and, if they agree with them, merge your pull request into the original repository. You've successfully collaborated on an external repository!