wiki:ControlSystems/SoftwareTeam/Training/Git

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:

  1. Go to: https://github.com/Team2537
  2. Navigate to RookiesTest
  3. Click the clone or download green button and copy the URL
  4. Open up FRC VS Code
  5. Press: Ctrl + Shift + P (A search bar will pop up)
  6. Type in "Git: clone" and click once it emerges
  7. Paste the URL from the github website and press enter
  8. 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/

  1. Click the plus sign at the top left of the page
  2. Click new repository
  3. Name the Repository HelloWorld
  4. Ignore the Description
  5. Leave it on the public button
  6. Check initialize README.md
  7. Click Create repository
  8. Click on the README.MD file and click the pencil icon to edit.
  9. in the next line, type #hello world
  10. Scroll down to "Commit Changes", type in "added hello" and press Commit changes
  11. Click the clone or download green button and copy the URL
  12. Open up FRC VS Code
  13. In Vs Code, Press: Ctrl + Shift + P (A search bar will pop up)
  14. Type in "Git: clone" and click once it emerges
  15. Paste the URL from the github website and press enter
  16. A tab will appear at the bottom right of the screen. Press "Open Repository"
  17. add a new file named "hello.java" by right-clicking under the README.md on the left
  18. Type in
      public class hello{
        public static void main(String args[]) {
            System.out.println("Hello World");
        }
      }
    
  19. Run it to check.
  20. Press: Ctrl + Shift + P (A search bar will pop up)
  21. Type in "Git: Commit"
  22. Two windows will pop up; say Yes to both.
  23. Type in "added hello.java" and press ENTER
  24. Press: Ctrl + Shift + P and type in Git: push.
  25. 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

Last modified 10 months ago Last modified on Jul 18, 2020, 12:07:19 PM