Making a Change - SWHS-PC/Users GitHub Wiki

This page describes the workflow you go to any time you want to make changes and get them into GIT. This assumes you've already cloned the repository, as described in Getting Started.

The Getting Started page walks through this process using the example of creating your first program. This page is intended mainly as a quick references, and doesn't repeat all the explanations in Getting Started.

Short version:

  1. Create a topic branch (git branch -b NameOfTopicBranch).
  2. Make changes and commit them locally (git add and git commit)
  3. Push changes to the remote repository (git push).
  4. Repeat steps 2 and/or 3 until you have something that's ready to review.
  5. Create a pull request.
  6. Optionally make changes based on feedback (and commit and push).
  7. Merge the pull request.

Creating the topic branch

You will create a branch for the purpose of making your change. This branch is referred to as a topic branch because it's dedicated to a particular purpose or topic.

The topic branch is created off of the main branch, so we'll first check out the main branch (if it isn't already), then make sure the main branch is up to date by pulling changes from the remote repo, and finally check out a new topic branch. Following are the commands:

cd c:\GitHub\SWHS-PC\Users
git checkout main
git pull
git checkout -b NameOfTopicBranch

The NameOfTopicBranch above is a placeholder for some unique name such as BobJ/Add-HelloWorld-Program.

Make changes and commit them to the local repository

This is the "inner loop" of your workflow. You can make a few changes, commit them, make a few more changes, commit those, and so on as many times as you want. Each time you have changes to commit, type the following commands:

git status
git add --all
git status
git commit --message "SomeDescriptiveComment"

The "git status" is optional, but is a good idea to make sure you're about to add (or commit) what you expect.

Alternatively, you can commit your changes from within Visual Studio.

Pushing changes to the remote repository

You can push changes to the remote repository every time you commit, or every few times, or only when you want to share them (such as before creating a pull request). It's up to you. To push changes, simply type:

git push

The first time you push from a new branch, this will give an error saying you need to specify the upstream branch. Simply copy the command line from the error message and press enter.

Create a pull request

Navigate to the page for the repository on GitHub.

Click the green "Compare & pull request" button to the right of your branch name.

Follow the instructions on the screen.

Make changes based on feedback

Address feedback from others by replying to their comments, making code changes, or both. If you make code changes, simply commit them and push them as you did before. The pull request is automatically updated each time you push changes to the branch.

Merge the pull request

When the pull request is approve, choose "Squash and Merge" to merge your changes into the main branch.

Say yes when prompted to delete the topic branch from the remote repository.

In your local repository, check out the main branch and pull changes from the remote repository as follows:

cd g:\GitHub\SWHS-PC\Users
git checkout master
git pull

You can now delete the topic branch from your local repository if you want:

git branch git branch -d NameOfTopicBranch

The "git branch" command with no arguments just lists what branches exist in your repository, and which one is checked out.