2014 MacAdmins Git Workshop
-
Upload
scott-gallagher -
Category
Technology
-
view
61 -
download
0
Transcript of 2014 MacAdmins Git Workshop
![Page 2: 2014 MacAdmins Git Workshop](https://reader034.fdocuments.us/reader034/viewer/2022042701/55be88d7bb61ebab768b4719/html5/thumbnails/2.jpg)
Session Feedback!
http://j.mp/psumac9
![Page 3: 2014 MacAdmins Git Workshop](https://reader034.fdocuments.us/reader034/viewer/2022042701/55be88d7bb61ebab768b4719/html5/thumbnails/3.jpg)
Part I - Git Basics
What is Version Control?
Why use it?
What is Git?
Git versus Subversion
Git Overview
![Page 4: 2014 MacAdmins Git Workshop](https://reader034.fdocuments.us/reader034/viewer/2022042701/55be88d7bb61ebab768b4719/html5/thumbnails/4.jpg)
What is Version Control?
Management of changes to documents like source code, scripts, text files
Provides the ability to check documents in and out of a repository
Version Control System (VCS)
Source Code Management (SCM)
![Page 5: 2014 MacAdmins Git Workshop](https://reader034.fdocuments.us/reader034/viewer/2022042701/55be88d7bb61ebab768b4719/html5/thumbnails/5.jpg)
What is Version Control?
"Version control is a system that records changes to a file or set of files over time so that you can recall specific versions later.” ( git-scm.com )
![Page 6: 2014 MacAdmins Git Workshop](https://reader034.fdocuments.us/reader034/viewer/2022042701/55be88d7bb61ebab768b4719/html5/thumbnails/6.jpg)
Why Use it?
You can revert and go back easily
Removes risk of updating your code
See process of steps you have taken
Fantastic tool that encourages collaboration
![Page 7: 2014 MacAdmins Git Workshop](https://reader034.fdocuments.us/reader034/viewer/2022042701/55be88d7bb61ebab768b4719/html5/thumbnails/7.jpg)
Why Use it?
Easy testing on multiple systems
Runs on Windows, Mac, and Linux!
Reuse of old code
Ability to go back in time! See how far you've come
Easy sharing and collaboration
![Page 8: 2014 MacAdmins Git Workshop](https://reader034.fdocuments.us/reader034/viewer/2022042701/55be88d7bb61ebab768b4719/html5/thumbnails/8.jpg)
What can I Use Git For?
ANY text based file
binary files too, but not as efficiently
Python, Bash, Perl, Ruby, scripts, text, config files, etc.
List is shorter of what you can’t use it for!
![Page 9: 2014 MacAdmins Git Workshop](https://reader034.fdocuments.us/reader034/viewer/2022042701/55be88d7bb61ebab768b4719/html5/thumbnails/9.jpg)
Git versus SubversionLightning fast! Checkouts are MUCH faster
Distributed versus centralized
No need for constant network access
Merging is much easier
Easier to ignore files and edit other properties
Git easily handles renaming and moving files
![Page 10: 2014 MacAdmins Git Workshop](https://reader034.fdocuments.us/reader034/viewer/2022042701/55be88d7bb61ebab768b4719/html5/thumbnails/10.jpg)
Git Overview
Git is distributed
You checkout and you have the full repo
Changes are applied locally first
Backups are everywhere!
Each member of your team has a local copy!
![Page 11: 2014 MacAdmins Git Workshop](https://reader034.fdocuments.us/reader034/viewer/2022042701/55be88d7bb61ebab768b4719/html5/thumbnails/11.jpg)
TerminologyRepository
Working Directory
Staging Area
Used for preparing commits
Git Directory
Repository object store/Remote Repository
Final destination for you data changes
![Page 12: 2014 MacAdmins Git Workshop](https://reader034.fdocuments.us/reader034/viewer/2022042701/55be88d7bb61ebab768b4719/html5/thumbnails/12.jpg)
Terminology
Working Directory
Index/ Staging
Directory/Repository
Local Local
Remote
Local
![Page 13: 2014 MacAdmins Git Workshop](https://reader034.fdocuments.us/reader034/viewer/2022042701/55be88d7bb61ebab768b4719/html5/thumbnails/13.jpg)
Git File ClassificationsTracked
Already in the repo
Ignored
Can exist but git ignores (specified in .gitignore)
Untracked
What's not tracked or ignored
![Page 14: 2014 MacAdmins Git Workshop](https://reader034.fdocuments.us/reader034/viewer/2022042701/55be88d7bb61ebab768b4719/html5/thumbnails/14.jpg)
Git File StatesModified
Changed but not yet committed
Staged
Modified filed marked to go into next commit
Committed
Safely stored in the repo
![Page 15: 2014 MacAdmins Git Workshop](https://reader034.fdocuments.us/reader034/viewer/2022042701/55be88d7bb61ebab768b4719/html5/thumbnails/15.jpg)
Git File States Lifecycle
![Page 16: 2014 MacAdmins Git Workshop](https://reader034.fdocuments.us/reader034/viewer/2022042701/55be88d7bb61ebab768b4719/html5/thumbnails/16.jpg)
Basic Git workflow
Working Directory
Staging Area
Repository
![Page 17: 2014 MacAdmins Git Workshop](https://reader034.fdocuments.us/reader034/viewer/2022042701/55be88d7bb61ebab768b4719/html5/thumbnails/17.jpg)
Example Workflow
git init
git add .
git commit -m “Added project files.”
git push
![Page 18: 2014 MacAdmins Git Workshop](https://reader034.fdocuments.us/reader034/viewer/2022042701/55be88d7bb61ebab768b4719/html5/thumbnails/18.jpg)
How Git Works
git init repo git add.
Creates .git folder in current
directory
1 2 3 git commit -m " "
Files committed to
local repo, ready to be
push to remote
git push (origin
master)
Files are pushed to repository
(final destination)
Add all files to be committed
![Page 19: 2014 MacAdmins Git Workshop](https://reader034.fdocuments.us/reader034/viewer/2022042701/55be88d7bb61ebab768b4719/html5/thumbnails/19.jpg)
Git Data IntegrityGit Checksums Everything!
Git uses SHA1 hash on all tracked files
It knows if anything has changed
Git excels at tracking renamed or moved files too
Resist modifying files when renaming or moving them
What about SHA1 hash collisions?
![Page 20: 2014 MacAdmins Git Workshop](https://reader034.fdocuments.us/reader034/viewer/2022042701/55be88d7bb61ebab768b4719/html5/thumbnails/20.jpg)
Git Help
Online docs are really, really good
http://git-scm.com
Command line help
git help
git help <conmand>
![Page 21: 2014 MacAdmins Git Workshop](https://reader034.fdocuments.us/reader034/viewer/2022042701/55be88d7bb61ebab768b4719/html5/thumbnails/21.jpg)
How to Install
git-scm.com/downloads
OS X: Terminal.app, Windows: Git Bash
Update to latest version
git clone https://github.com/git/git
Embedded with many Git GUI client apps
![Page 22: 2014 MacAdmins Git Workshop](https://reader034.fdocuments.us/reader034/viewer/2022042701/55be88d7bb61ebab768b4719/html5/thumbnails/22.jpg)
How to Configure
$ git config
Contains items such as name, email, editor, diff tool
![Page 23: 2014 MacAdmins Git Workshop](https://reader034.fdocuments.us/reader034/viewer/2022042701/55be88d7bb61ebab768b4719/html5/thumbnails/23.jpg)
How to Configure$ git config
Located in 3 places
/etc/gitconfig -- Values for all users
~/.gitconfig -- Values for single user
.git/config -- Value for single repository
$ git config --list
![Page 24: 2014 MacAdmins Git Workshop](https://reader034.fdocuments.us/reader034/viewer/2022042701/55be88d7bb61ebab768b4719/html5/thumbnails/24.jpg)
Configure Line EndingsEnd of line characters differ based on client OS
Windows uses two invisible characters
CR (Carriage Return)
LF (Line Feed)
OS X and Linux use one invisible character
LF (Line Feed)
Embrace the native line endings for each OS to be HAPPY
![Page 25: 2014 MacAdmins Git Workshop](https://reader034.fdocuments.us/reader034/viewer/2022042701/55be88d7bb61ebab768b4719/html5/thumbnails/25.jpg)
Line Ending Modescore.autocrlf true
Recommended for cross platform projects from Windows clients
core.autocrlf input
Recommended for cross platform projects from OS X / Linux / Unix clients
core.autocrlf false
Recommended only for single platform projects
![Page 26: 2014 MacAdmins Git Workshop](https://reader034.fdocuments.us/reader034/viewer/2022042701/55be88d7bb61ebab768b4719/html5/thumbnails/26.jpg)
Line Endings on Windows
Enable auto convert to LF on Windows by using git config to set core.autocrlf to true:
![Page 27: 2014 MacAdmins Git Workshop](https://reader034.fdocuments.us/reader034/viewer/2022042701/55be88d7bb61ebab768b4719/html5/thumbnails/27.jpg)
Line Endings on OS X
On OS X, enable auto convert CRLF to LF:
![Page 28: 2014 MacAdmins Git Workshop](https://reader034.fdocuments.us/reader034/viewer/2022042701/55be88d7bb61ebab768b4719/html5/thumbnails/28.jpg)
Creating Repositories
git init ProjectName.git
Initializes a new and clean repository in new directory
git clone <repoURL> <directory>
The process of copying an existing Git repository locally to your computer
Copies the entire repository history and file revisions
![Page 29: 2014 MacAdmins Git Workshop](https://reader034.fdocuments.us/reader034/viewer/2022042701/55be88d7bb61ebab768b4719/html5/thumbnails/29.jpg)
Ignoring Files
Git ignore files, paths specified in the .gitignore file
Specifies files/folders that are not tracked via Git
Wildcards
*NotForRepo*, *.dmg, etc.
10.9.4-Lab-Image.dmg
LargeDataFile-NotForRepo.db
![Page 30: 2014 MacAdmins Git Workshop](https://reader034.fdocuments.us/reader034/viewer/2022042701/55be88d7bb61ebab768b4719/html5/thumbnails/30.jpg)
Status of File ChangesHow do I know what has changed?
$ git status
Status reports different states
Untracked
Modified
Staged
![Page 31: 2014 MacAdmins Git Workshop](https://reader034.fdocuments.us/reader034/viewer/2022042701/55be88d7bb61ebab768b4719/html5/thumbnails/31.jpg)
DifferencesCommits are all about what is … different!
Viewing the differences
At the command line
$ git diff FileName
In GUI Apps
Kaleidoscope, FileMerge, Changes.app, etc.
![Page 32: 2014 MacAdmins Git Workshop](https://reader034.fdocuments.us/reader034/viewer/2022042701/55be88d7bb61ebab768b4719/html5/thumbnails/32.jpg)
Staging Files
Added files are staged
Why not just directly commit the changes?
git add -v <file/folder_name>
git add -v .
git add -A
![Page 33: 2014 MacAdmins Git Workshop](https://reader034.fdocuments.us/reader034/viewer/2022042701/55be88d7bb61ebab768b4719/html5/thumbnails/33.jpg)
Unstaging Files
File not yet tracked but staged:
$ git rm --cached NewFile.txt
Files already tracked in repo, revert to previous
$ git reset HEAD FileName.txt
![Page 34: 2014 MacAdmins Git Workshop](https://reader034.fdocuments.us/reader034/viewer/2022042701/55be88d7bb61ebab768b4719/html5/thumbnails/34.jpg)
Committing ChangesThis process saves the revisions made to the repository
Commit often - You will thank yourself later!
Or else! Larger changes are much harder to pick apart and revert back to.
Each commit should encapsulate a single fix*
git commit -m <commit_message>
What's the most important part of the above command?
![Page 35: 2014 MacAdmins Git Workshop](https://reader034.fdocuments.us/reader034/viewer/2022042701/55be88d7bb61ebab768b4719/html5/thumbnails/35.jpg)
Pushing to Remote Repos
Local versus Remote (Hosted) Repos
Commit changes to local repo first, then push all to remote repo(s)
Cloning from a remote host
Branching from a remote/local host
Read/Write versus Read-Only Accounts
![Page 36: 2014 MacAdmins Git Workshop](https://reader034.fdocuments.us/reader034/viewer/2022042701/55be88d7bb61ebab768b4719/html5/thumbnails/36.jpg)
Accessing Remote ReposNetwork Based
HTTPS
SSH
Git Protocol (daemon)
Multiple Remotes
Fetch updates
Pruning Local Branches
![Page 37: 2014 MacAdmins Git Workshop](https://reader034.fdocuments.us/reader034/viewer/2022042701/55be88d7bb61ebab768b4719/html5/thumbnails/37.jpg)
Viewing Changes
Logs
$ git log --shows all pulls + info about each
![Page 38: 2014 MacAdmins Git Workshop](https://reader034.fdocuments.us/reader034/viewer/2022042701/55be88d7bb61ebab768b4719/html5/thumbnails/38.jpg)
Git LogUsed for git reset
![Page 39: 2014 MacAdmins Git Workshop](https://reader034.fdocuments.us/reader034/viewer/2022042701/55be88d7bb61ebab768b4719/html5/thumbnails/39.jpg)
Git Log
List changes made in a commit
git log
View entire change log
$ git log -p -2
Lists changes in last two commit entries
![Page 40: 2014 MacAdmins Git Workshop](https://reader034.fdocuments.us/reader034/viewer/2022042701/55be88d7bb61ebab768b4719/html5/thumbnails/40.jpg)
Reverting Changesgit reset
Change back to file state at specific commit
git revert
Creates a new commit and undoes last changes
git checkout <commit> -- <filename>
Changes branch you’re currently working on
![Page 41: 2014 MacAdmins Git Workshop](https://reader034.fdocuments.us/reader034/viewer/2022042701/55be88d7bb61ebab768b4719/html5/thumbnails/41.jpg)
Hands On Git DemoCommand Line
Install
Configure
Create new repo
Add to .gitignore
Add files
Commit changes
Add remote
Push Items
Revert Items
Clone Existing Repo
![Page 42: 2014 MacAdmins Git Workshop](https://reader034.fdocuments.us/reader034/viewer/2022042701/55be88d7bb61ebab768b4719/html5/thumbnails/42.jpg)
GUI Clients
SourceTree (OS X and Windows)
GitHub (OS X and Windows)
Tower (OS X)
http://git-scm.com/downloads/guis
![Page 43: 2014 MacAdmins Git Workshop](https://reader034.fdocuments.us/reader034/viewer/2022042701/55be88d7bb61ebab768b4719/html5/thumbnails/43.jpg)
Diff GUI Applications
FileMerge
Changes.app
Kaleidoscope is totally AWESOME!
![Page 44: 2014 MacAdmins Git Workshop](https://reader034.fdocuments.us/reader034/viewer/2022042701/55be88d7bb61ebab768b4719/html5/thumbnails/44.jpg)
SourceTree In Depth DemoInstall
Configure
.gitignore
Create New Repo
Adding Items
Commit Items
Push Items
Revert Items
Clone Existing Repo
![Page 45: 2014 MacAdmins Git Workshop](https://reader034.fdocuments.us/reader034/viewer/2022042701/55be88d7bb61ebab768b4719/html5/thumbnails/45.jpg)
SourceTree In Depth DemoBookmarks List
Recommended Git Defaults
Line Endings
Host Repositories Feature
Working Directory, Branches, Searching
Excellent Git Flow Integration
![Page 46: 2014 MacAdmins Git Workshop](https://reader034.fdocuments.us/reader034/viewer/2022042701/55be88d7bb61ebab768b4719/html5/thumbnails/46.jpg)
Kaleidoscope Demo
Using Kaleidoscope for diffs, conflicts, merges
Excellent support for Git and SourceTree
![Page 47: 2014 MacAdmins Git Workshop](https://reader034.fdocuments.us/reader034/viewer/2022042701/55be88d7bb61ebab768b4719/html5/thumbnails/47.jpg)
Part II - Advanced GitFetching
Tags
Branches
Merging
Origin (Remotes)
HEAD Reference
Pushing to Remotes
Automate Authentication
Advanced Git Ignores
Stashing
Advanced Diffs
Searching
Moving Files
Bisect
Pull Requests
![Page 48: 2014 MacAdmins Git Workshop](https://reader034.fdocuments.us/reader034/viewer/2022042701/55be88d7bb61ebab768b4719/html5/thumbnails/48.jpg)
Fetching
Get updates from remote repo
Does not apply changes to local working directory
Useful to run before doing a pull
$ git fetch origin
![Page 49: 2014 MacAdmins Git Workshop](https://reader034.fdocuments.us/reader034/viewer/2022042701/55be88d7bb61ebab768b4719/html5/thumbnails/49.jpg)
TagsUseful for marking a specific commit
Example: Mark commit that is for major version change
1.0.1
1.0.2
Useful for regression testing with the ‘git bisect’ command
![Page 50: 2014 MacAdmins Git Workshop](https://reader034.fdocuments.us/reader034/viewer/2022042701/55be88d7bb61ebab768b4719/html5/thumbnails/50.jpg)
Tags
Create a tag syntax
$ git tag <commit hash ID>
![Page 51: 2014 MacAdmins Git Workshop](https://reader034.fdocuments.us/reader034/viewer/2022042701/55be88d7bb61ebab768b4719/html5/thumbnails/51.jpg)
Branches
“master” branch is the default
Helps to separate lines of development
Ex: Master, Hotfix, Development, Feature, Release
Merging of branches is where Git excels
“Git Flow” is a popular branching model
![Page 52: 2014 MacAdmins Git Workshop](https://reader034.fdocuments.us/reader034/viewer/2022042701/55be88d7bb61ebab768b4719/html5/thumbnails/52.jpg)
BranchesCreate and switch to new branch
$ git checkout -b <branch>
Checkout (switch to) branch
$ git checkout master
Delete branch
$ git branch -d <branch>
![Page 53: 2014 MacAdmins Git Workshop](https://reader034.fdocuments.us/reader034/viewer/2022042701/55be88d7bb61ebab768b4719/html5/thumbnails/53.jpg)
Deleting Branches
Delete Remote Branch
$ git push origin —delete <branchname>
Don’t forget to delete all stale remote-tracking branches!
$ git remote prune origin
Otherwise your local repo will still show it
![Page 54: 2014 MacAdmins Git Workshop](https://reader034.fdocuments.us/reader034/viewer/2022042701/55be88d7bb61ebab768b4719/html5/thumbnails/54.jpg)
Merging Changes
Demo of the merge process
Conflicts
Cherry Picking
Show how to change diff tool to GUI app
![Page 55: 2014 MacAdmins Git Workshop](https://reader034.fdocuments.us/reader034/viewer/2022042701/55be88d7bb61ebab768b4719/html5/thumbnails/55.jpg)
Merging Changes
Use FileMerge for merging conflicts
$ git mergetool -t opendiff
![Page 56: 2014 MacAdmins Git Workshop](https://reader034.fdocuments.us/reader034/viewer/2022042701/55be88d7bb61ebab768b4719/html5/thumbnails/56.jpg)
Remotes
Default is called "origin" (leave it this name)
Versus Local Repo
Multiple
Primary, off site, etc.
Be careful that local branches still track the primary repo branch after adding more remotes
![Page 57: 2014 MacAdmins Git Workshop](https://reader034.fdocuments.us/reader034/viewer/2022042701/55be88d7bb61ebab768b4719/html5/thumbnails/57.jpg)
Automate Authentication
SSH Remote Host
Create Open SSH Key pair, place id_rsa.pub key on remote host
HTTPS
Credential Helpers for command line
SourceTree and other GUI apps manage this well
![Page 58: 2014 MacAdmins Git Workshop](https://reader034.fdocuments.us/reader034/viewer/2022042701/55be88d7bb61ebab768b4719/html5/thumbnails/58.jpg)
Adding a Remote Repo
$ git remote add origin ssh://user@host/path/to/repo.git
![Page 59: 2014 MacAdmins Git Workshop](https://reader034.fdocuments.us/reader034/viewer/2022042701/55be88d7bb61ebab768b4719/html5/thumbnails/59.jpg)
HEAD Reference
HEAD is a reference to branch or a specific commit
What does "detached HEAD" mean, and why should I care?
Working directory state points to specific commit and not latest commit on a branch
![Page 60: 2014 MacAdmins Git Workshop](https://reader034.fdocuments.us/reader034/viewer/2022042701/55be88d7bb61ebab768b4719/html5/thumbnails/60.jpg)
Pushing Changes
git push origin master
Pushes all your commits on master branch to the origin remote
Push to other locations
git push
![Page 61: 2014 MacAdmins Git Workshop](https://reader034.fdocuments.us/reader034/viewer/2022042701/55be88d7bb61ebab768b4719/html5/thumbnails/61.jpg)
Advanced Git IgnoresGlobal Git Ignore File in ~/.gitignore
Git tracks files, not directories
By default, Git does not track empty directories
![Page 62: 2014 MacAdmins Git Workshop](https://reader034.fdocuments.us/reader034/viewer/2022042701/55be88d7bb61ebab768b4719/html5/thumbnails/62.jpg)
Add Empty Dir to RepoCreate a .gitignore file in the directory to ignore
Ignore all files except the .gitignore file
![Page 63: 2014 MacAdmins Git Workshop](https://reader034.fdocuments.us/reader034/viewer/2022042701/55be88d7bb61ebab768b4719/html5/thumbnails/63.jpg)
Stashing ChangesVery useful for when you’re not ready to commit the changes to the repo yet
Saves your changes to the local Git repo and does not commit them
Stash the changes (makes working directory clean)
$ git stash
Restore the changes
$ git stash pop
![Page 64: 2014 MacAdmins Git Workshop](https://reader034.fdocuments.us/reader034/viewer/2022042701/55be88d7bb61ebab768b4719/html5/thumbnails/64.jpg)
Advanced Diffs
Logging Changes of one file
Tags
git diff <tag1> <tag2>
Branches
git diff branch1..branch2
![Page 65: 2014 MacAdmins Git Workshop](https://reader034.fdocuments.us/reader034/viewer/2022042701/55be88d7bb61ebab768b4719/html5/thumbnails/65.jpg)
Searching
Search file names, commit messages
$ git log -S<string>
RegEx for commit messages
$ git log -G”RegEx Pattern Here”
![Page 66: 2014 MacAdmins Git Workshop](https://reader034.fdocuments.us/reader034/viewer/2022042701/55be88d7bb61ebab768b4719/html5/thumbnails/66.jpg)
Who Made Changes?
List who modified what files
git blame -l FileName.txt
git blame -l —show-email FileName.txt
![Page 67: 2014 MacAdmins Git Workshop](https://reader034.fdocuments.us/reader034/viewer/2022042701/55be88d7bb61ebab768b4719/html5/thumbnails/67.jpg)
Moving Files Demo
Git excels at moving files
When moving or renaming files do NOT modify them for most efficient commit
Recall that everything is checksummed, Git knows if a file is the same one regardless if the name changed
![Page 68: 2014 MacAdmins Git Workshop](https://reader034.fdocuments.us/reader034/viewer/2022042701/55be88d7bb61ebab768b4719/html5/thumbnails/68.jpg)
Hunting For Bugs
Git provides a very handy function to help find which commit introduced a bug
You tell Git what commit point was good and bad
$ git bisect start
$ git bisect bad # Current version is bad
$ git bisect good v2.6.13-rc2
![Page 69: 2014 MacAdmins Git Workshop](https://reader034.fdocuments.us/reader034/viewer/2022042701/55be88d7bb61ebab768b4719/html5/thumbnails/69.jpg)
Advanced Demo
Detached HEAD
Configure Remote
Push Changes to remote
Moving Files, Stashing
Branching
Merging, Tagging
Diffs
Searching
GitFlow
Bisect
![Page 70: 2014 MacAdmins Git Workshop](https://reader034.fdocuments.us/reader034/viewer/2022042701/55be88d7bb61ebab768b4719/html5/thumbnails/70.jpg)
Repo Hosting ServicesGitHub, BitBucket, Google Code
CodeSpaces, SourceRepo
Assembla, Gitorious
GitLab
Git.psu.edu for Penn Staters
Lots more!
![Page 71: 2014 MacAdmins Git Workshop](https://reader034.fdocuments.us/reader034/viewer/2022042701/55be88d7bb61ebab768b4719/html5/thumbnails/71.jpg)
Self-Hosted Repos
SSH
Atlassian Stash
Enterprise GitHub
GitLab
![Page 72: 2014 MacAdmins Git Workshop](https://reader034.fdocuments.us/reader034/viewer/2022042701/55be88d7bb61ebab768b4719/html5/thumbnails/72.jpg)
Git FlowWorkflow for managing branches
Five different branch types
Feature
Develop
Release
Hotfixes
Master
![Page 73: 2014 MacAdmins Git Workshop](https://reader034.fdocuments.us/reader034/viewer/2022042701/55be88d7bb61ebab768b4719/html5/thumbnails/73.jpg)
Removing Tracked Files
$ git rm —cached <FileName>
Update repo .gitignore to ignore the file(s)
![Page 74: 2014 MacAdmins Git Workshop](https://reader034.fdocuments.us/reader034/viewer/2022042701/55be88d7bb61ebab768b4719/html5/thumbnails/74.jpg)
Removing Untracked Files
$ git status
$ git clean -n
Dry run, shows what would be deleted
$ git clean -f
Removes the files listed in previous command
![Page 75: 2014 MacAdmins Git Workshop](https://reader034.fdocuments.us/reader034/viewer/2022042701/55be88d7bb61ebab768b4719/html5/thumbnails/75.jpg)
Tips and Tricks
Aliases
Can be used to shorten commands
Pros and Cons on shared systems
Auto-Completion
Auto completes Git commands; like Linux
![Page 76: 2014 MacAdmins Git Workshop](https://reader034.fdocuments.us/reader034/viewer/2022042701/55be88d7bb61ebab768b4719/html5/thumbnails/76.jpg)
Best Practices
Handling Very Large Repos
run `git gc` every 100 or so commits
http://blogs.atlassian.com/2014/05/handle-big-repositories-git/
Simple solution is a shallow clone
git clone --depth depth remote-url
![Page 77: 2014 MacAdmins Git Workshop](https://reader034.fdocuments.us/reader034/viewer/2022042701/55be88d7bb61ebab768b4719/html5/thumbnails/77.jpg)
What's New in Git 2.0
Default push changes
Simple versus matching
git push (with no arguments) defaults to simple push mechanics
git add now includes removals to the repo
Pre 2.0 only added new or modified files
![Page 78: 2014 MacAdmins Git Workshop](https://reader034.fdocuments.us/reader034/viewer/2022042701/55be88d7bb61ebab768b4719/html5/thumbnails/78.jpg)
Lessons Learned
Write good commits messages!
Really helps when writing release notes
Easy to search
Helps future self!
![Page 79: 2014 MacAdmins Git Workshop](https://reader034.fdocuments.us/reader034/viewer/2022042701/55be88d7bb61ebab768b4719/html5/thumbnails/79.jpg)
Lessons Learned
Take the time to write good commit messages when they are fresh in your mind
There will be a time when you need to search your commit messages and it will really help you out.
Be nice to your future self
“Where / when / how did I fix that issue?”
![Page 80: 2014 MacAdmins Git Workshop](https://reader034.fdocuments.us/reader034/viewer/2022042701/55be88d7bb61ebab768b4719/html5/thumbnails/80.jpg)
Lessons LearnedSubmodules and dependencies
Branch Names
No White Space Permitted (tabs, spaces)
Supports Hierarchical Names*
‘bug/pr-1023’, ‘bug/pr-17’
$ git show-branch ‘bug/*’
![Page 81: 2014 MacAdmins Git Workshop](https://reader034.fdocuments.us/reader034/viewer/2022042701/55be88d7bb61ebab768b4719/html5/thumbnails/81.jpg)
Lessons Learned
Tags
Use "annotated" most of the time
Working with others
Team collaboration tips
![Page 82: 2014 MacAdmins Git Workshop](https://reader034.fdocuments.us/reader034/viewer/2022042701/55be88d7bb61ebab768b4719/html5/thumbnails/82.jpg)
Lessons LearnedStart small
Pick one project to implement Git
Use just the develop and master branches at first, add additional branches as you get more comfortable
Watch commits on GitHub, fork a project, create pull requests
![Page 83: 2014 MacAdmins Git Workshop](https://reader034.fdocuments.us/reader034/viewer/2022042701/55be88d7bb61ebab768b4719/html5/thumbnails/83.jpg)
Lessons Learned
Using a VCS/SCM makes you more mobile and code tested on more environments makes that project more robust.
Commenting helps to clarify your comments, design flow, and for code review
![Page 84: 2014 MacAdmins Git Workshop](https://reader034.fdocuments.us/reader034/viewer/2022042701/55be88d7bb61ebab768b4719/html5/thumbnails/84.jpg)
Further Reading
Cherry Picking
Patches
Reflog
Rebasing
![Page 85: 2014 MacAdmins Git Workshop](https://reader034.fdocuments.us/reader034/viewer/2022042701/55be88d7bb61ebab768b4719/html5/thumbnails/85.jpg)
ResourcesGit Docs
http://git-scm.com/documentation
Git cheat sheets
Lynda.com (lynda.psu.edu)
Git Essential Training, GitHub for Web Designers
Fundamentals of Software Version Control
![Page 86: 2014 MacAdmins Git Workshop](https://reader034.fdocuments.us/reader034/viewer/2022042701/55be88d7bb61ebab768b4719/html5/thumbnails/86.jpg)
Resources
Atlassian Git Tutorials
https://www.atlassian.com/git/tutorial
https://try.github.io
O'Reilley Books
“McCullough and Berglund on Mastering Git”
![Page 87: 2014 MacAdmins Git Workshop](https://reader034.fdocuments.us/reader034/viewer/2022042701/55be88d7bb61ebab768b4719/html5/thumbnails/87.jpg)
Thank You!
![Page 88: 2014 MacAdmins Git Workshop](https://reader034.fdocuments.us/reader034/viewer/2022042701/55be88d7bb61ebab768b4719/html5/thumbnails/88.jpg)
Please submit Session Feedback!
http://j.mp/psumac9