This section summarizes the git commands you will need when creating feature branches for your semester-long project.

1. Create and check out a local branch for the current milestone

When you start a new milestone, you need to create a local branch to hold your work. For example, if you wanted to create a feature branch for Milestone 0, you would do:

$ git branch ms0

Next, check out your new branch. For our Milestone 0, we would do:

$ git checkout ms0

2. Work on the new branch

As you make progress on the current milestone, it is a good idea to add your changes to the remote repository. First, make sure you are on your milestone branch by doing:

$ git branch

You will see a list of all local branches, with a * next to the currently checked out branch. You should see that the branch for the current milestone has a *. Then, add, commit, and push the changes for your branch to the remote repository:

$ git add .
$ git commit -m "description of changes"
$ git push

The first time you do this, it will automatically create a remote branch with the same name.

Info

Depending on your git configuration, you may get this error when you git push or git pull on a local branch that has no remote counterpart:

fatal: The current branch <branchName> has no upstream branch.
To push the current branch and set the remote as upstream, use

    git push --set-upstream origin <branchName>

To have this happen automatically for branches without a tracking
upstream, see 'push.autoSetupRemote' in 'git help config'.

If you get this error, you can update your git configuration as follows:

git config --global push.autoSetupRemote true

At that point you should be able to use git push or git pull and have it go automatically to/from the corresponding remote branch.

(If you still have errors, you will first need to update your version of git to get a version that is at least 2.37 – you can check the version number with git --version.)

3. Continuing work on a different computer

Suppose you followed the steps above to start a milestone on your home computer (including pushing the latest changes for your milestone branch) and wanted to continue working on a lab computer.

First time working with the repository

If this was your FIRST time working on this repository on the new computer, you would need to clone the repository to the new local machine. You can do this with Visual Studio’s File->Clone Repository or from the terminal with git clone [repoURL].

First time working with current branch

If you have already cloned this repository to your current local computer but have not yet created a branch on this computer for the current milestone, you can use the git checkout option to both create a new local branch with the same name as a remote branch and switch to that new branch:

$ git checkout -b ms0 origin/ms0

Replacing ms0 with the current milestone branch.

Subsequent times working with a branch

If you have previously worked with the current milestone branch on your local computer, you need to first checkout that branch:

$ git checkout ms0

Again, replacing ms0 with the current milestone branch. Then, pull the latest changes for that branch from the remote repository to the local repository. If you do:

$ git pull origin ms0

It will fetch updates from the remote ms0 branch and merge them into the local ms0 branch.

Merging your feature branch into main

Finally, when you have finished the milestone, you’ll want to merge your new changes from the feature branch into the main branch:

$ git checkout main 
$ git merge ms0

(Again, replacing ms0 with the current milestone branch name). Next, push the newly expanded main branch to GitHub:

$ git push origin main

After that, you’ll need to create a release to turn in.