Move out Subversion; there's a new man in town. Learn how a decentralized version control system can help make your workflow easier, regardless of what language you use. We'll walk through how to manage a project using Git, and use some branching, tagging, recovery, and a host of other features along the way. Come see how easy it is to branch and merge without the usual headaches.
I'm going to make you an offer you can't refuse
This is very important. I have a vital meeting to attend, and I've just shot myself in the leg.
Let's talk merger.
I decided I can write something better than anything out there in two weeks. And I was right.
git init
git add .
git commit -m "Initial commit"
Add then commit:
git add newfile.txt
git add trackedfile.txt
git commit -m "Updated trackedfile, added newfile"
Shorthand:
git commit -am "Added all changes to tracked files"
Grab a remote repository:
git clone git://github.com/gisikw-slides/use-git-like-a-boss.git cd use_git_like_a_boss/
Pull changes:
git pull origin master
Push changes
git push origin master
In the future, we use GitHub!
git branch gh-pages git checkout gh-pages #> Switched to branch "gh-pages" slideshow slides.md git commit -am "Generated slides" #> [master 0adc9ff] Generated slides #> 0 files changed, 0 insertions(+), 0 deletions(-) #> create mode 100644 slides.html #> create mode 100644 slides.pdf ...
git checkout master #> Switched to branch "master" ls #> slides.md #> Rakefile
They say a cluttered desk means a cluttered mind.
You want my advice? Well I'm not going to give it to ya.
git checkout master #> Switched to branch "master" git merge experimental #> Auto-merging conference.rb #> Merge made by recursive.
CONFLCIT (content): Merge conflict in conference.rb Automatic merge failed; fix conflicts and then commit the result.
class Conference def best_presentation <<<<<<< HEAD "Kevin's, of course" ======= "Ola Bini's talk" >>>>>>> experimental end end
class Conference def best_presentation "Kevin's, of course" end end
git commit -am "Fixed merge conflict, Kevin's presentation is vastly superior"
Actually, given that we can merge instantaneously, I'm not gonna need you to come in on Saturday anymore. Yeah..........
git branch --track muwahaha milton/stapler #> Branch muwahaha set up to track remote branch stapler from milton. git checkout muwahaha #> Switched to branch 'muwahaha'
git pull milton stapler #> Pull the stapler branch into the current system git push milton stapler #> Push the current system to the stapler branch
Bob is excited about Git!
This is not "Take Your Problems to Work Day". It's just "Work Day"
git svn clone https://svn.kde.org/home/kde/trunk/kdesupport/strigi
#> SCREEN SPAM OF ADDED FILES
cd strigi
...
Push commits to Subversion:
git svn dcommit
Pull changes from Subversion:
git svn rebase
This is the type of trickery I pay you for.
git reset --hard # Discard everything since the last commit git reset --hard ORIG_HEAD # Discard the most recent successful merge git reset --soft HEAD^ # Undo the last commit - keep the changes locally git commit --amend # Redo the last commit, with additional changes
.gitignore
Tagging
Shashing
Submodules
Hooks
The Cathedral:
Commit when you're done
Merging is expensive - limit your branching
Always have server access
I am the SERVER thy God. Thou shalt have no stranger servers before Me.
The Bazaar:
Commit is equivalent to auto-save
Branch for everything - don't convalute features
Keep the repository local
Use external servers as common points, but remember that there is no single "right way" to write code
Thank you!
Kevin W. Gisi <kevin@kevingisi.com>