How to use the GitHub Branch System - MDHSRobotics/TeamWiki GitHub Wiki

PreFace/Explanations

  1. While in Eclipse, check the end of your program for something like this. TestingProgram [TestingProgram master] The first "TestingProgram" is the name of the current project. The second "TestingProgram" is the name of the project on GitHub. The "master" is the branch.
  2. When you first create a project, there is only one version of it. However, if you want someone to work on it without messing up the original, then you would create a branch. At this point, there would be the master (the main code) and a variation (lets call this 1A). This can continue from the master code. Meaning there can be a 2A, 3A, etc. This can also spread out from 1A, meaning there can potentially be 1B, 1C, etc.
  3. This can get confusing, so when working on a project, it's important that you pay attention to what branch you are editing. The tutorial below will provide all that you need.

Before creating a new branch

You must open on your computer:

  • Eclipse
  • Git Bash
  • Command Prompt

The Tutorial Part 1

  1. Use the previous tutorial to clone the project into eclipse then check the tag at the end to see what version you want to edit. Considering that the branch is the master/main branch example
  2. In Eclipse when you look at the Project Explorer, you should see something along the lines of TestingProgram [TestingProgram master]. Check above for explanation on the naming.
  3. You can then make changes to the code however you want.
  4. Next open up 'git bash' and 'command prompt' and on both navigate to the folder where your projects are (the folder where TestingProgram resides).
  5. From here you can commit normally to the main branch, but beware that the rest of the code in the other branches will be affected.

The Tutorial Part 2

  1. Now that the master branch is changed to your liking, say that you want to create a branch. For our example, say the name of the new branch is called "TestingProgramV1." Use git bash to create the branch.
  • git checkout -b branchname creates a new branch (remember to check what branch from which you are branching off. If you want to make a different variation of the master, make sure the branch is the master version in git bash. You can also name this branch whatever you want)

You can edit the code however you want. After, make you upload your branch to GitHub. You should know your login before performing this step.

  • git push origin branchname to finalize changes in GitHub
  1. Next use this command to switch in between branches.
  • git checkout branchname switches to branch branchname
  1. If two people are working on 1 branch, and want the code on two separate computers, pull the branch using this line.
  • git clone -b branchname pulls branch branchname
  1. To make anymore commits (do this before pushing code)
  • git commit branchname