How to code with multiple computers without causing conflicts

When you are working on a project, you may want to use multiple computers. This is common for students who work on their assignments at home and at school.

To do this, you need to make sure that you are using GitHub correctly to avoid conflicts. Here are the steps to follow:

  1. Make sure you have Git installed on all computers.
  2. Clone your GitHub repository to each computer.
  3. Before you start working, pull the latest changes from GitHub.
  4. When you finish working, commit your changes and push them to GitHub.
  5. Before switching computers, always pull the latest changes from GitHub.

By following these steps, you can work on your project from multiple computers without causing conflicts. If you do encounter a conflict, Git will help you resolve it.

For more information on how to use Git and GitHub, you can refer to the GitHub Quickstart Guide.

Remember to always commit your changes and push them to GitHub before switching computers. This will ensure that your work is saved and can be accessed from any computer.

Here are the step-by-step instructions

Follow the instructions found in the Setup New Computer. These instructions are specific to school work and you may have to do other things for work setup.

Open VSCode on your computer and go to the Source Control icon

Source Control icon

Then click on the 3 dots to the right of Changes and select Branch - Create New Branch

Create New Branch

Enter a name for your branch, such as "dev" and press Enter. The branch name can be anything you want to use.

Enter New Branch Name

Click the Publish Branch button that appears at the top of the Source Control panel. This will create the branch on GitHub and set it as the current branch in VSCode.

Publish Branch

Now you can make changes to your code without affecting the main branch. When you are ready to save your changes, you can commit them to the new branch. You can verify that you are on the new branch by checking the branch name in the bottom left corner of the VSCode window.

Check Branch Name

Now you can make all the edits you want on this computer. To use the same branch on another computer, you need to follow these steps:

  1. Commit and sync your changes from the original computer to GitHub.
  2. Open VSCode on the new computer.
  3. Clone your GitHub repository to the new computer if not already on your computer.
  4. Open the Source Control panel and click on the 3 dots to the right of Changes.
  5. Select Branch - Checkout to Branch and choose the branch you created.
Checkout Branch

Now you can continue working on the same branch on the new computer. Remember to always pull the latest changes from GitHub before making any changes, and push your changes when you are done.

Make sure to always do a pull request before you start to work on the new computer.

Git Pull Request

If you ever get a Merge Conflict and you are not sure how to fix that, contact your instructor or refer to this video on YouTube that shows you how to fix a merge conflict. Mastering Merge Conflicts in VS Code

Merging dev branch to main branch to publish on GitHub Pages

As you push changes to GitHub, you may see the following message in Github on the Code page of your repository. You can ignore this until you are ready to merge it into the main branch.

Auto Pull Request Notice

Once you are ready to publish your code so that it is available on GitHub Pages for grading, follow these steps.

  1. Make sure you are on the dev branch in VSCode.
  2. Commit all your changes to the dev branch.
  3. Push the dev branch to GitHub.
  4. Go to GitHub and create a pull request from the dev branch to the main branch.
  5. Review the changes and merge the pull request.
  6. Switch back to the main branch in VSCode.
  7. Pull the latest changes from the main branch.
  8. Now your main branch is up to date with the dev branch.
New Pull Request

You will then select the main branch as the base branch and the dev branch as the compare branch.

Compare Branches

The web page will then fill in and it will look something like this.

Compare Pull Request

Click on the "Create pull request" button to create the pull request.

GitHub will then show you the changes that will be merged into the main branch. You can review the changes and make sure everything looks good.

Once you are satisfied with the changes, you can add a title and description for the pull request. This will help you and others understand what changes were made and why. The screen will look something like this.

Pull Request Title

After you have added a title and description, click on the "Create pull request" button. This will create the pull request and notify the repository owner that there are changes ready to be reviewed. The owner in this case is you.

After you have created the pull request, you will see the page to merge the pull request. This will only show you the Merge ull request button if there are no conflicts with the code in the main branch. If there are conflicts you will have to decide how to handle the conflict so that you can merge the other changes into main.

Pull Request Details

You can add more details in the comment area below the button. That is not necessary as you should be the only one making changes. This part is mainly used when there are multiple developers working on a project.

Click on the "Merge pull request" button to merge the changes from the dev branch into the main branch.

After you click the "Merge pull request" button, GitHub will show you a confirmation page. You can review the changes one last time before merging. Click the Confirm merge button to finalize the merge.

Merge Pull Request Confirmation

Once you confirm the merge, GitHub will merge the changes from the dev branch into the main branch. You will see a message indicating that the pull request was successfully merged.

Pull Request Merged

Once the pull request is merged, Give the system a couple of minutes and your changes will be live on GitHub Pages.