Git is the most popular program for software version control which helps track changes in code when multiple people are working on the same set of files, allows you to save versions of your work and return to them later, see differences between versions, and even share work with other team members. Git is like the google docs of software development. Git is widely used in industry; expect to use it or something like it daily if you become a software engineer.
Make sure to download git on windows at: https://git-scm.com/download/win
Download for git on Mac is at: https://git-scm.com/download/mac
While we can use the Git download for software development, VSC, the environment you have been using to write and run your code, has built in commands for git which we will be using for this tutorial.
Now create an account on Github.
Example 1:
- Go to: https://github.com/Team2537
- Navigate to RookiesTest
- Click the clone or download green button and copy the URL
- Open up FRC VS Code
- Press: Ctrl + Shift + P (A search bar will pop up)
- Type in "Git: clone" and click once it emerges
- Paste the URL from the github website and press enter
- A tab will appear at the bottom right of the screen. Press "Open Repository"
You have just cloned your first repository! By using VSC and the GitHub website, you've made a copy of the code on the website.
Team Development Commands For git to be truly effective, you have to be able to make changes as a team. Commands include:
- git commit - once you've edited your copy of code, this command records your changes and lets you leave a note.
- git add - adds new files you've created inside the code.
- git push - this command uploads your committed changes to the main repo on the website
- git clone (what we first used) - creates a copy on your computer not effected by other people's edits
- git merge -when two or more users make changes at the same time, conflicts will occur. VSC will ask you if you'd like to merge, meaning combining users' codes and having you manually edit any errors.
Example 2: 1.Go to https://github.com/
- Click the plus sign at the top left of the page
- Click new repository
- Name the Repository HelloWorld
- Ignore the Description
- Leave it on the public button
- Check initialize README.md
- Click Create repository
- Click on the README.MD file and click the pencil icon to edit.
- in the next line, type #hello world
- Scroll down to "Commit Changes", type in "added hello" and press Commit changes
- Click the clone or download green button and copy the URL
- Open up FRC VS Code
- In Vs Code, Press: Ctrl + Shift + P (A search bar will pop up)
- Type in "Git: clone" and click once it emerges
- Paste the URL from the github website and press enter
- A tab will appear at the bottom right of the screen. Press "Open Repository"
- add a new file named "hello.java" by right-clicking under the README.md on the left
- Type in
public class hello{ public static void main(String args[]) { System.out.println("Hello World"); } }
- Run it to check.
- Press: Ctrl + Shift + P (A search bar will pop up)
- Type in "Git: Commit"
- Two windows will pop up; say Yes to both.
- Type in "added hello.java" and press ENTER
- Press: Ctrl + Shift + P and type in Git: push.
- Check on github to see your changes.
Other terminology:
- Branches - when you want to focus on different assets in the code, it may be best to create a branch. This way, you won't have to deal with merge conflicts and can commit your changes freely. For example, often in our robot code, we will have a branch devoted to Arm mechanism or Autonomous version. Check the SpaceBase Repository on https://github.com/Team2537/Spacebase and click on the left-most white button "Branch: Main". Explore the other branches what differences or similarities do you see?
Past years resources
- GitLab Server (source code) - see: Alex Taber for username/password access