Git Basics

From FRC11 - Mentor Wiki
Jump to navigation Jump to search

About Source Control

Git is a great tool for Source Control. Source Control is all about saving, sharing, and managing your source code, whether working independently, or together. It is a significant element of Configuration Management (CM), and Version Control, which deal with managing changes to a Software System (or other systems of information).

For example, did we want to run this upcoming event after bringing in Billy's latest efforts on the Nav system? Did he finish it? Test it fully? Did Joey mess it up thinking it was fixed? CM provides a structured approach to approving changes to the software baseline and pulling them into a release of the software.

Source Control is the first step in a good CM process. It makes sure we save our work, gets it backed up in case we lose our hard drive, and share our work with others. It allows us to roll back to a previous version of working code (if something was broken badly), identify changes that were made and when, and who made those changes. It can allow us to make sure we have the latest appropriate code from everyone, but we each have to be responsible for getting the latest code. We have to take this last step of getting latest to make sure our code works with the latest code, and doesn't break anything.

We use Git for our source control tool, and use Gitlab and sometimes Github to host the repositories and provide a web interface. Although we can use the command line, and the IDEs (IntelliJ or Visual Studio) can perform Git commands, we also use Git Extensions or TortoiseGit as a GUI front end for Git, which gives us a very nice interface.

Git Basics

Git Vocabulary

Version Control System or Source Control: A system that manages source code for controlling what goes INTO a software version release, and provides a mechanism for making changes and tracking those changes. Your exposure to Source Control is the program to send information to and from the server.

Server: External computer other computers connect to. Runs software to collect and provide information to Clients (you)

Repository: A database that holds the source code. There is usually a local repository on your machine, and one remote repository on the Server. (Usually).

Clone: Bring an external project (repository) to your computer to work on it. (Usually only done once, at the beginning.)

Checkout: Unpack the source code in the local repository, and place it into your Working Folder. (Works on a Branch.)

Working Folder: A directory on your local machine that the code is unpacked into, and where you make your changes.

Commit: Save changes locally (into your local repository) from your Working Folder. Not yet shared with anyone. (Works on a Branch.)

Push: Send local changes (ones that have already been commited) to the server (the shared repository). (Works on a Branch.)

Fetch: Bring server changes into your local repository, but not yet into your working folder. (Works on a Branch.)

Pull: Pull others’ changes that have been pushed to the server, and merge into your working directory. (Does NOT get changes that have only been committed to the other engineer's local repository.) Does a fetch and a merge. The merge could require you to manage conflicts. (Works on a Branch.)

Branch: A split from a development line to manage changes. Usually, you Create a Branch, Checkout a branch to your working folder, Commit your branch, and push your branch. When you create a branch, you need to think about what you are going to create the branch from. Usually, it's origin/master, but not always.

master: The main development line. Pretty much a branch, but it didn't split from anywhere previously. This is often protected from just anyone pushing changes. (See "Pull Request", below.)

origin/master: There is a master branch in the Server repository, and one in your local repository. "Origin" is the default name for items on the server. So origin/master is the master branch on the server.

Pull Request: You can make your own branch, and you can pull from origin/master to update your branch, and you can check into your own branch, and you can push your branch to the server repository, but your code will never get into the main line (master) unless you can merge into origin/master. This is usually protected. The way to get your code in, is after you have done the above, you issue a Pull Request and then the git Admin will consider the changes and then merge them into origin/master.

User Setup

Git User Setup

Git Tutorials

Git Presentation By Dan Steinmark: PDF PowerPoint

Git for Dummies

Getting Started with Git. See Chapters 1 and 2.

Our Code Repositories

See our Code page

More Git

Git Basic Commands at Atlassian

Git Graphical User Interfaces

Git Command Line

Git Administration

Jerry's Git Notes

Command Line Git

With your pubic key in the gitlab.mort11.org site, you can simply work command line using ssh by default.

1. Clone a repo

     git clone git@gitlab.mort11.org:programming/mort_u_robot.git

2. Now see what you have:

     jerry.olup@dev0105u16:~/work/IdeaProjects/mort_u_robot$ git branch
     * master
 >> this tells us that we cloned the repo and by default have the master

3. But what's the span of this repo - what all is in it?

     jerry.olup@dev0105u16:~/work/IdeaProjects/mort_u_robot$ git branch -a
     * master
       remotes/origin/Ganesh
       remotes/origin/HEAD -> origin/master
       remotes/origin/Kevin
       remotes/origin/Matt
       remotes/origin/Nick
       remotes/origin/master
       remotes/origin/vedh
   >> "git branch -a lists all local (*master) and remote (all remotes) branches.  
   >> ok now we know what we can draw from, let's switch the HEAD to a branch. 
   >>    Kevin just declared victory, let's check his repo out.

4. To now checkout Kevin's repo;

     - git checkout -b kevin remotes/origin/Kevin
     - git fetch origin

5. Verify this is good: git branch -a

     * kevin
       master
       remotes/origin/Ganesh
       remotes/origin/HEAD -> origin/master
       remotes/origin/Kevin
       remotes/origin/Matt
       remotes/origin/Nick
       remotes/origin/master
       remotes/origin/vedh
  >> Now Kevin and master are local, kevin is active and they are all of 
  >>   course on the remote server.


"If you use Subversion, you're stupid."

          - Linus Torvalds