saving time and headaches
WITH GIT AND MORE
seemaisms
seemaullal
Seema Ullal
Overview
What is Git
Setting Up Your Terminal
Useful Git Commands
Merging
Rebasing
Interactive Rebasing
Have a Good Readme
What is Git
Setting Up Your Terminal
Useful Git Commands
Merging
Rebasing
Interactive Rebasing
Have a Good Readme
Git is a distributed version control system that stores data using snapshots of changes over time
Distributed
Everyone has a local copy of the code – a local repository that is contained in the .git folder
You usually also have a remote, central repository with the shared code (Github, Bitbucket, etc)
Snapshots
various states of how the code looked at different times
COMMIT OFTEN– you can easily go to different "milestones" in your code
What is Git
Useful Git Commands
Merging
Rebasing
Interactive Rebasing
Setting Up Your Terminal
Have a Good Readme
What I Use...
good starting points
Git autocomplete
Git autocomplete
Step 2: Add to your .bash_profile or .bashrc (or zsh)
source ~/.git-completion.bash
Step 1: Download the script
Git Aliases
Git Hooks
What is Git
Setting Up Your Terminal
Merging
Rebasing
Interactive Rebasing
Useful Git Commands
Have a Good Readme
git stash
lets you "save your changes for later". also useful for moving your changes from one branch to another
# on a branch 1
git stash save half-done-feature
# technically can just do git stash
# now you can switch branches!
# ... later
git stash pop
# (or git stash apply if you don't want
# to delete the stash)
git stash
lets you "save your changes for later". also useful for moving your changes from one branch to another
# show a list of all your stashes
git stash list
# shows all the file changes in a stash
git stash show
# can specify which stash by adding
`stash@{<stash-number>}` after any command
git COMMIT -P
A safer way to commit. Also allows you to commit parts of a file. Shows you each section you changed and asks if you want to commit it.
// dangerous! Who knows what you are commiting
git commit -am 'Made some awesome changes'
// instead, double check everything you are commiting
git commit -p 'Made some awesome changes'
// can also do git add -p
git COMMIT -P
A safer way to commit. Also allows you to commit parts of a file. Shows you each section you changed and asks if you want to commit it.
amending commits
Note: Use with caution. Allows you to amend a previous commit. Good for changing commit messages or fixing small errors you made.
# add the file(s) with the changes you want
git add -p
git commit --amend
# (can optionally edit commit message here)
git push -f
# force push only if amended commit already on
# Github (not a good sign!)
"UNDO" last Commit
useful alternative to stashing
( create a "temporary" commit then undo later)
also a quick way to fix committing on the wrong branch
# create a temporary work in progress commit
git add -A
git commit -m 'wip'
# switch branches, make unrelated changes,
# do whatever else you wish to do
# go back to your branch with the 'wip' commit
git reset HEAD^
# now there is no 'wip' commit but all of its changes still exist
# the "^" is actually short for "HEAD^1"
you can also specify how many commits to go back:
git reset HEAD^2 or git reset HEAD~2
see http://www.paulboxley.com/blog/2011/06/git-caret-and-tilde
uh oh...
what if you "git reset" and then change your mind?
Others
git diff
git status
git log
git blame <file_name>
git grep <reg_exp>
git revert
git checkout -- <file_name>
git cherry-pick <commit>
... and many more!
useful tip
Highly recommend using an IDE that has built in version control (PyCharm, WebStorm, RubyMine, PHPStorm, etc.) or a graphical interface for Git (Github for Mac, Source Tree, etc.)
What is Git
Setting Up Your Terminal
Useful Git Commands
Rebasing
Interactive Rebasing
Merging
Have a Good Readme
Merging
common
ancestor
Branch A
Branch B
# on branch A
git merge branchB
c1
c0
c2
Merging
common
ancestor
Branch A
Branch B
# on branch A
git merge branchB
c1
c0
c2
c4
merge commit
What is Git
Setting Up Your Terminal
Useful Git Commands
Merging
Interactive Rebasing
Rebasing
Have a Good Readme
rebasing
# on branchA
git rebase branchB
common
ancestor
Branch A
Branch B
c1
c0
c2
rebasing
# on branchA
git rebase branchB
common
ancestor
Branch B
c1
c0
c2
Branch A
rebasing
# on branchA
git rebase branchB
common
ancestor
Branch A
c1
c0
c2
Branch B
rebasing
# on branchA
git rebase branchB
common
ancestor
Branch A
c1
c0
c2
Branch B
Rebasing rewrites history.
Use it with caution.
Overview
What is Git
Setting Up Your Terminal
Useful Git Commands
Merging
Rebasing
Interactive Rebasing
Have a Good Readme
interactive rebasing
demo
Overview
What is Git
Setting Up Your Terminal
Useful Git Commands
Merging
Rebasing
Have a Good Readme
HAVE A GOOD README.
- download your repo to run it
- try to figure out how to run your app
- guess what your app does
- wonder why you made whatever you made
Things people don't want to (and probably won't) do:
a good readme...
- screenshots
-
clickable table of contents
-
features
-
steps to run the app (include info on seeding, etc.)
-
link to a deployed version [include this if screenshots don't do your project justice]
-
next steps
-
contributors
-
how to contribute
-
license
* must haves
learn more!
Pro Git book **
** = highly recommended
questions?
Seema Ullal
seemaisms
seemaullal
www.seemaullal.com/blog
Git It
By Seema Ullal
Git It
Talk at Hackbright Academy
- 3,478