// Contains all of the project files
// Stores each file's revision history
// Can have multiple collaborators
// Can be either public or private
// There will be multiple copies
// There is usually one central “master” copy
// A Git repository that is nested within another repository
// It's codebase is managed independently of its
container's code
// Does not automatically upgrade
// A parallel version of a repository
// Does not affect the primary master branch
// Publish your changes by merging the branch
back into the master branch
// The version of the
repository that is hosted on
a remote server (GitHub)
// Local repository is
connected to the remote
so that changes can
be synced
// Holds the current checkout of the files
you are working on
// Files in will be removed or replaced by Git
as you switch branches
// A staging area
// Holds snapshots of changes are before they get
committed to the repository
// A snapshot of the tracked contents of your
working directory
// Records what changes were made when and by who
// Tracked using a unique 40 character SHA1 hash
// Typically used to mark a particular commit using
a memorable name
// Specify which files and directories Git should ignore
// Committed into repository in order to share ignore
rules with other users that clone the repository
# Files
.DS_Store
error_log
# File types
*.log
# Directories
node_modules/
wp-content/cache/
# Ignore everything in wp-content except plugins and themes
wp-content/*
!wp-content/plugins/
!wp-content/themes/
$ git --version
// Global configuration
[user]
name = Bill Swath
email = user@example.com
[color]
ui = true
[core]
excludesfile = /Users/swath/.gitignore_global
filemode = false
editor = subl -n -w
~/.gitconfig
// Global configuration
$ git config --global user.name "[name]"
$ git config --global user.email "[email address]"
# Colorful output
$ git config --global color.ui auto
# Don't track file permission changes
$ git config --global core.filemode false
// Project configuration
[core]
...
[remote "origin"]
url = git@github.com:VitalDevTeam/Skeleton.git
fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
remote = origin
merge = refs/heads/master
[submodule "wp"]
url = https://github.com/WordPress/WordPress.git
project/.git/config
// Identify trusted computers and servers without
using passwords
// Required to push changes to remote
// Required to clone private repositories
init
$ git init
Initialized empty Git repository in /Users/vitaldesign/Dropbox/GitHub/test/.git/
$ ls -alh
total 0
drwxr-xr-x@ 3 vitaldesign 501 102B Jul 9 12:19 ./
drwxr-xr-x@ 25 vitaldesign 501 850B Jul 9 12:19 ../
drwxr-xr-x@ 10 vitaldesign 501 340B Jul 9 12:19 .git/
Create a new repository locally
clone
$ git clone git@github.com:VitalDevTeam/Nucleus.git nucleus
Cloning into 'nucleus'...
remote: Counting objects: 1548, done.
remote: Total 1548 (delta 0), reused 0 (delta 0), pack-reused 1548
Receiving objects: 100% (1548/1548), 1.17 MiB | 1.79 MiB/s, done.
Resolving deltas: 100% (915/915), done.
Checking connectivity... done.
Clone existing repository locally
clone
SSH URL
Requires SSH key
HTTPS URL
Asks for password on every push
clone --recursive
$ git clone --recursive git@github.com:VitalDevTeam/Skeleton.git skeleton2
Cloning into 'skeleton2'...
remote: Counting objects: 458, done.
remote: Total 458 (delta 0), reused 0 (delta 0), pack-reused 458
Receiving objects: 100% (458/458), 877.96 KiB | 0 bytes/s, done.
Resolving deltas: 100% (190/190), done.
Checking connectivity... done.
Submodule 'wp' (https://github.com/WordPress/WordPress.git) registered for path 'wp'
Cloning into 'wp'...
remote: Counting objects: 208388, done.
remote: Compressing objects: 100% (179/179), done.
remote: Total 208388 (delta 106), reused 0 (delta 0), pack-reused 208209
Receiving objects: 100% (208388/208388), 130.03 MiB | 2.49 MiB/s, done.
Resolving deltas: 100% (164374/164374), done.
Checking connectivity... done.
Submodule path 'wp': checked out '0b63a9e4b66eff7826bd7319ef767d24d9b55775'
Clone existing repository and all submodules locally
add
# Add individual files
$ git add <filename> <filename> <filename> ...
# Add all files that have been changed
$ git add -u
# Add all files that have been changed AND new files
$ git add -A
Add your local changes to the staging area (index)
add -p
Add local changes to the staging area in hunks instead of whole files
status
$ 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: bomp.php
no changes added to commit (use "git add" and/or "git commit -a")
Shows the differences between your working directory, the index, and previous commits
commit
$ git commit -m 'Added awesome widget'
[master 68aa034] Added awesome widget
1 files changed, 2 insertions(+), 1 deletions(-)
Takes the staged snapshot in the index and commits it to the project history
Commit a lot as you go!
commit -m
Commit message best practices:
// First line should be 50 characters or less
// Second line should be blank
// Omit the -m flag if you need to write more
than 50 characters
// Describe what the commit does to the repo and
not what YOU did
commit
Adds FAQs
Adds new custom post type plugin for FAQs
as well as 2 content block layouts for the FAQs.
# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
# On branch master
#
# Initial commit
#
# Changes to be committed:
# new file: foo
#
Good example of a longer commit message
commit
Change your default editor in Git so you can write commit messages easily:
On remote servers where you can't use apps:
$ git config --global core.editor "nano"
push
$ git push origin master
Counting objects: 25, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (25/25), done.
Writing objects: 100% (25/25), 2.43 KiB, done.
Total 25 (delta 4), reused 0 (delta 0)
To git@github.com:foo/bar.git
* [new branch] master -> master
Send your committed changes to a remote repository
fetch
// Get the latest changes from the
remote repository without merging them
// Changes can be compared to your local copy
$ git fetch origin
remote: Counting objects: 4006, done.
remote: Compressing objects: 100% (1322/1322), done.
remote: Total 2783 (delta 1526), reused 2587 (delta 1387)
Receiving objects: 100% (2783/2783), 1.23 MiB | 10 KiB/s, done.
Resolving deltas: 100% (1526/1526), completed with 387 local objects.
From github.com:foo/bar
8e29b09..c7c5a10 master -> origin/master
pull
Fetch and merge changes from the remote repository to your local copy
log
View the history of a repository
# View verbose commit history
$ git log
# View simple, one line commit history
$ git log --pretty=oneline
# View commit history with graphical branch chart
$ git log --name-status
$ git branch <branch>
Create a new branch
$ git checkout <branch>
Switch to a branch
$ git push origin <branch>
Push branch to remote so others have access to it
$ git merge <branch>
Merge branch into current
// 2 people make edits on the same line
// One person deletes a file that another was
working on
// 2 people add a file with the same name
Quick Reference Guide
http://rogerdudler.github.io/git-guide/
More Comprehensive Tutorial
https://www.git-tower.com/learn/git/ebook
Interactive 15-Minute Basic Tutorial
Interactive Branching Tutorial
http://pcottle.github.io/learnGitBranching