Git

Thanks

AJ made most of these slides

So. Git.

Technical definition:

Git is a distributed version control system.

Better definition:

Git is a piece of software that helps you keep track of your software.

Why Git?

Keeps a history of your code

Undo on steroids

Handles conflicts (merges) (more on this later)

Also:

GitHub cat logoGitHub wordmark

Collaboration

Old Method: USB

Now: Shared on the cloud

Everyone has their own version

Versions are merged together

Let's begin - do this once.

First: make a repository on your local computer.

This is called initializing.

$ pwd
/home/nathan/Programming/Projects_in_cs/Robotic/

$ git init
Initialized empty Git repository in
/home/nathan/Programming/Projects_in_cs/Robotics/.git/

$ git status
On branch master
Initial commit
nothing to commit (create/copy files and use "git add" to track)

Add some code

$ echo "Readme" > README.md

$ git add README.md

$ git commit -m "Initial Commit"

Sync with GitHub

Find the URL on your GitHub page.

$ git remote add origin https://github.com/Garfield-HS-Projects/TANK.git

$ git push origin master

For everyone else

All other team members need to do this.

You only need to do this once.

$ git clone https://github.com/Garfield-HS-Projects/TANK.git

Make some changes...

$ echo 'Hello, world!' > README.md
$ git status
On branch master
Your branch is up-to-date with 'origin/master'.
Changes not staged for commit:
    (use "git add ..." to update what will be committed)
    (use "git checkout -- ..." to discard changes in working directory)
    
    modified:   README.md
    
no changes added to commit (use "git add" and/or "git commit -a")

When in doubt,

git status

Commits

The working directory is what you see in your editor.

The staging area is where you queue changes to commit them.

A commit is a snapshot of your repository at a particular point in time.

A picture is worth 1000 words (assumes x86)

Git staging area diagram

Commit some changes

git add takes stuff in the working directory and stages it

You need to git add every time you change stuff - not just when you add new files!

git commit commits the changes in the staging area

Example

$ git status
On branch master
Your branch is up-to-date with 'origin/master'.
Changes not staged for commit:
    (use "git add ..." to update what will be committed)
    (use "git checkout -- ..." to discard changes in working directory)
    
    modified:   README.md
    
no changes added to commit (use "git add" and/or "git commit -a")

$ git add README.md

$ git commit -m "Made README say hello."
[master cca3472] Made README say hello.
 1 file changed, 1 insertion(+), 1 deletion(-)

What just happened?

We made some changes

We staged them, with git add

We committed, with git commit

$ git status
On branch master
Your branch is ahead of 'origin/master' by 1 commit.
  (use "git push" to publish your local commits)
nothing to commit, working directory clean

We did it!

We used git status, because we always use git status

Then we used git log to see a log of all our commits (there's only one so far)

Pushing

We've been working locally so far

We want to share

GitHub

GitHub

Free online hosting for Git

"Social coding"

GitHub != Git

Example

$ git pull
Username for 'https://github.com': NathanMer
Password for 'https://NathanMer@github.com': 
Already up-to-date.

$ git push
    Username for 'https://github.com': NathanMer
    Password for 'https://NathanMer@github.com':
    Counting objects: 3, done.
    Writing objects: 100% (3/3), 276 bytes | 0 bytes/s, done.
    Total 3 (delta 0), reused 0 (delta 0)
    To https://github.com/Garfield-HS-Projects/TANK.git
      d6ff69b..cca3472  master -> master
    

"Hey, Git! Take the local branch master, and push (upload) it to the origin remote."

Merge Conflicts!

Sometimes two people edit the same file in a way git can't fix

This can usually be avoided by spliting your project into parts

Each person should only edit the files for their part.

Then people will not be editing the same files.

Access this presention again

http://saasrobotics.com/presentation-git-your-ftc-on

QR code to presentation URL

Or, git clone the source.