supportDocs

How NOT to Create a New Repository When Fixing Code After a Review Using GitHub Desktop

When working on fixing code following a review, it’s crucial to avoid creating a new repository or a new project entirely. This guide explains how to make fixes in your existing project, push changes to the same remote repository using GitHub Desktop, and what to do if you create a new project by mistake.

1. Making Code Fixes in the Existing Project

Step-by-Step Guide:

  1. Open Your Project in GitHub Desktop:
    • Open GitHub Desktop.
    • From the top bar, select File > Open… and choose the existing project you’ve been working on. This will ensure you’re working in the same repo.
  2. Fix the Code in the Same Project:
    • Make the necessary code changes in your IDE (e.g., IntelliJ, Visual Studio Code).
    • Important: Do not create a new project. All changes should be made within the existing project directory.
  3. Commit Your Changes in GitHub Desktop:
    • In GitHub Desktop, you will see the changes you made in the left panel under Changes.
    • Write a commit message describing your changes (e.g., “Fixes after code review”).
    • Click the Commit to main button to commit your changes locally.
  4. Push to the Same Remote Repository:
    • After committing, click the Push origin button in GitHub Desktop to push your changes to the remote repository.
    • This will ensure that the changes are pushed to the same remote repo as before.

Common Pitfalls to Avoid:

2. Avoid Creating a New Project

If you’re fixing code after a review, avoid creating a new project in your IDE. Instead, use the existing project and make changes within it.

Why?

3. If You Accidentally Create a New Project

If you mistakenly created a new project but want to push it to the original remote repository, here’s how you can reconnect to the correct repo using GitHub Desktop:

  1. Open the New Project in GitHub Desktop:
    • In GitHub Desktop, click File > Add Local Repository….
    • Navigate to the folder of your new project and select it.
  2. Change the Remote URL to the Correct Repository:
    • Go to Repository > Repository Settings.
    • Under Remote, check if the URL is incorrect or missing. If it is wrong, paste the URL of the original GitHub repository.
      • To get the correct URL, visit your GitHub repo on the website, click the Code button, and copy the URL.
    • Click Save to set the remote URL.
  3. Stage, Commit, and Push:
    • Now that your project is linked to the correct remote repository, stage the changes, commit them in GitHub Desktop, and push them to the original repo by clicking Push origin.

What to Avoid:

4. Reconnecting to a Remote Repo in an Existing Project

If you’ve lost connection to your remote repository, follow these steps to reconnect in GitHub Desktop:

  1. Check the Remote URL:
    • In GitHub Desktop, go to Repository > Repository Settings and check the remote URL.
  2. Add or Correct the Remote URL:
    • If the remote URL is incorrect or missing, paste the correct GitHub repository URL.
    • Click Save to ensure your project is connected to the right repo.
  3. Push Your Changes:
    • After setting the correct remote, push your changes by clicking Push origin in GitHub Desktop.

5. Final Tips

By following these steps, you ensure that your code remains in the correct repository and is well-managed, avoiding confusion and redundancy.








If you want to do the same but with command line, see below!



How NOT to Create a New Repository When Fixing Code After a Review Using Command Line/Terminal/Shell

When working on fixing code following a review, it’s crucial to avoid creating a new repository or a new project entirely. This guide explains how to make fixes in your existing project, push changes to the same remote repo, and what to do if you create a new project by mistake.

1. Making Code Fixes in the Existing Project

Step-by-Step Guide:

  1. Open Your Project in the IDE:
    • Open the project in your IDE (e.g., IntelliJ, Visual Studio Code) that is already linked to the remote repository.
  2. Fix the Code in the Same Project:
    • Make the necessary code changes based on the code review.
    • Important: Do not create a new project or repository for these fixes. All the changes should be made within the same project directory.
  3. Commit Your Changes Locally:
    • Once the fixes are made, commit your changes:
      git add .
      git commit -m "Fixes after code review"
      
  4. Push to the Same Remote Repository:
    • Push your changes to the remote repository using:
      git push origin main
      
    • If you’re working on a different branch, replace main with the appropriate branch name.

Common Pitfalls to Avoid: