AKRON
WOMEN IN TECH

PRESENTS

GIT IN CHARGE OF YOUR CODE

WHAT IS

Git?

Git

Git is a free and open source distributed version control system designed to handle everything from small to very large source code projects with speed and efficiency.

WHAT IS A

Version Control System?

Version Control System

A VCS is a system that records changes to a file or set of files over time so that you can recall specific versions later.

Repository

server

Kevin's Laptop

localhost

Rachel's Laptop

localhost

Where do I start?

Web-based Git repository hosting service.

  • ∞ - Free public repositories.
  • 0 - Free private repositories.
  • Paid plans starting at $7/mo

Web-based Git repository hosting service.

  • ​∞ - Free public repositories.
  • 5 - Free private repositories.
  • Paid plans starting at $10/mo

Installing Git

Let's Start Fresh!

Creating a Repo

Use GitHub or Bitbucket to create a new repository following the steps on their website.

cd Sites/
mkdir git-in-charge-of-your-code
cd git-in-charge-of-your-code
echo "# git-in-charge-of-your-code" >> README.md
git init
git add README.md
git commit -m "first commit"
git remote add origin https://github.com/wirthdesign/git-in-charge-of-your-code.git
git push -u origin master

Repository
github.com

Kevin's Laptop

localhost

WOAH,

I Got Code Already

cd already-existing-code/
git init
git remote add origin https://github.com/wirthdesign/git-in-charge-of-your-code.git
git add -A
git commit -m "First commit"
git push -u origin master

Repository
github.com

Kevin's Laptop

localhost

Pull Command

git pull

The pull command will bring in the latest changes pushed to your repo.

Repository
github

Kevin's Laptop

localhost

Removing Files

git rm

Use this git command to remove a file from your repository. If removing a directory you need to pass additional options.

git rm README.md

rm 'README.md'


git rm -r cheeseburgers/

rm cheeseburgers/

Adding Files

git add

Use this git command to add files individually or pass -A to add all files with uncommitted changes.

git add path/to-the/file/README.md


git add -A

Cloning Repos

git clone <repo>

The clone command will pull down a repository you don't have already.

cd Sites/
git clone https://github.com/wirthdesign/spaceapps.git

Cloning into 'spaceapps'...
remote: Counting objects: 977, done.
remote: Total 977 (delta 0), reused 0 (delta 0), pack-reused 977
Receiving objects: 100% (977/977), 2.19 MiB | 1.36 MiB/s, done.
Resolving deltas: 100% (469/469), done.
Checking connectivity... done.

Repository
github.com/wirthdesign/spaceapps

Kevin's Laptop

localhost

File Status

git status

On branch master
Your branch is up-to-date with 'origin/master'.

Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)

	deleted:    README.md

Reset

git status

On branch master
Your branch is up-to-date with 'origin/master'.

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

	modified:   app/assets/javascripts/templates/layouts/profile.hbs
	modified:   app/assets/javascripts/templates/profiles/file_attachments.hbs
	modified:   app/assets/stylesheets/sass/style.scss
	modified:   app/assets/stylesheets/style.css

Untracked files:
  (use "git add <file>..." to include in what will be committed)

	app/assets/images/icons/attachments-blue.png
	app/assets/images/icons/attachments-blue_2x.png
	app/assets/images/icons/attachments-gray.png
	app/assets/images/icons/attachments-gray_2x.png

no changes added to commit (use "git add" and/or "git commit -a")
git reset --hard

HEAD is now at 323532e first commit

Repository
github.com

Kevin's Laptop

localhost

LETS TALK

Workflow

Branching

STEP 1.

Feature Branches

The master branch is sacred! Keep it production ready in case of an emergency fix. All new features or fixes should go into branches.

source

git branch add-paypal-integration
git checkout add-paypal-integration

Switched to branch 'add-paypal-integration'

STEP 2.

Create Feature

git add -A
git commit -m "Added PayPal integration to payment methods."

[add-paypal-integration 3598464] Added PayPal integration to payment methods.
    6 files changed, 6 insertions(+)
    create mode 100644 classes/
    create mode 100644 classes/paypal.php
    create mode 100644 classes/paypal/
    create mode 100644 classes/paypal/expresscheckout.php
    create mode 100644 config/
    create mode 100644 config/paypal.php

git push --set-upstream origin add-paypal-integration

Counting objects: 6, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (6/6), done.
Writing objects: 100% (6/6), 265 bytes | 0 bytes/s, done.
Total 6 (delta 0), reused 0 (delta 0)
To https://github.com/wirthdesign/git-in-charge-of-your-code.git
 * [new branch]      add-paypal-integration -> add-paypal-integration
Branch new-feature set up to track remote branch new-feature from origin.

STEP 3.

Merging into Master

git checkout master

Switched to branch 'master'
Your branch is up-to-date with 'origin/master'.

git merge add-paypal-integration

Updating 323532e..3598464
Fast-forward
 classes/                           | 1 +
 classes/paypal.php                 | 1 +
 classes/paypal/                    | 1 +
 classes/paypal/expresscheckout.php | 1 +
 config/                            | 1 +
 config/paypal.php                  | 1 +
 6 files changed, 6 insertions(+)
 create mode 100644 classes/
 create mode 100644 classes/paypal.php
 create mode 100644 classes/paypal/
 create mode 100644 classes/paypal/expresscheckout.php
 create mode 100644 config/
 create mode 100644 config/paypal.php

git push

Total 0 (delta 0), reused 0 (delta 0)
To https://github.com/wirthdesign/git-in-charge-of-your-code.git
   323532e..3598464  master -> master

Conflicts!

git conflicts

Sometimes when you pull or merge code you will get file conflicts. Conflicts need to be resolved and appear in your terminal with a C next to them.

<html>

<head>
    <title>Put a bird on it!</title>
</head>

<body>

<h1>Let's put a bird on it!</h1>

<<<<<<< HEAD
<p>The dog is BLUE</p>
=======
<p>The cat is WOOF</p>
>>>>>>> 213123213124141241234124

</body>
</html>
<html>

<head>
    <title>Put a bird on it!</title>
</head>

<body>

<h1>Let's put a bird on it!</h1>

<p>The dog is BLUE</p>

</body>
</html>

QUESTIONS?

RESOURCES

Understanding the GitHub Flow

https://guides.github.com/introduction/flow/

 

Git Branching - Basic Branching and Merging

http://git-scm.com/book/en/v2/Git-Branching-Basic-Branching-and-Merging

AWiT: Git in Charge of Your Code

By Akron Women In Tech

AWiT: Git in Charge of Your Code

  • 2,070