git obstacle course: stop bashing your head and break down the basics

82
Git Obstacle Course Stop BASHing your head and break down the basics

Upload: chris-bohatka

Post on 08-Jan-2017

400 views

Category:

Technology


0 download

TRANSCRIPT

Git Obstacle Course Stop BASHing your head and break down the

basics

about me• Cleveland, OH

• .NET Web Developer

• CardinalCommerce

• @cjb5790

• http://chris.bohatka.com

why should I get git?• decentralized

• works offline (default)

• flexible

• lightweight

• widely supported

• better control

install git (windows)

install git (windows)

install git (mac)

now what?

lets create our first repo

but how?

tools

github for windows

atlassian sourcetree

axosoft gitkraken

git bash• shell running in cygwin

• cygwin = terminal

• terminal = program that runs a shell

• shell = program that runs commands

• console = type of terminal

command line (CLI)

Terminal

=

Bash

basic bash commands

ls list files in current directory

cd change current directory

touch create a new blank file

rm remove a file

mv “move” - rename file

mkdir create a new directory

rmdir remove a directory

rm -rf remove directory and contents

more show the contents of a file

creating a repo

git init

add files

git add <filename>

stage• all files that will be committed, but have not been committed yet

git ignore

let’s commit

how to commit

git commit

but before we commit...

...ALWAYS diff!

ALWAYS diff

git diff

git difftool

git difftool -t <tool name>

git difftool

git difftool

git config --global diff.tool kdiff3

git != svn | tfs | vss

git commit

git commit -a

git commit -a -m

git commit -a -m “[commit message]”

commit early, commit often

branches

branches• branching is EXTREMELY cheap in git

• performant

• easy (straight-forward)

• you will branch A LOT

• most branches will be local only

• branch life expectancy is very short

branches

git branch shiny-new-feature

git checkout shiny-new-feature

git checkout• switches active branch

• doesn’t actually ‘pull’ any files

• unless you “git fetch”

creating a branch

removing a branch

git merge

git merge <name-of-branch>

git mergetool• resolve merge conflicts using GUI of your choice

• KDiff3 - http://kdiff3.sourceforge.net

• AraxisMerge - http://www.araxis.com/merge/index.en

git mergetool -t <tool name>

git mergetool

git config --global mergetool.kdiff3.path /Applications/kdiff3.app/Contents/MacOS/kdiff3

git mergetool

git mergetool -t kdiff3

git mergetool

git config --global merge.tool kdiff3

git mergetool

git mergetool

remotes

Remote(GitHub, Bitbucket,

etc)

Clone #1(My PC)

Clone #2(Co-Worker’s

PC)

repository hosts

https://github.com https://bitbucket.org

how to pull/push

git pull

git push

git revert & reset• revert

• single commit

• reset

• all changes since last commit

git revert <commit> git reset

git cherry-pick

git cherry-pick <revision>

gitflow• promotes positive development workflow

• easily differentiates new features and bugs

• streamlines release management

• allows easy “logging” of changes

* http://nvie.com/posts/a-successful-git-branching-model/

tags

git tag -a <version> -m <commit message>

git tag -a v1.0 -m ‘MVP launch’

git aliases• git command

• stores in git config file

• user specific

git config --global alias.nameOfAlias “command to alias”

git aliases

git config --global alias.hadouken ‘push’

git config --global alias.cm ‘commit -a -m’

git config --global alias.glog ‘log --graph’

commit with alias

bash aliases• shell level shortcut

alias nameOfAlias=“command to alias”

bash aliases

alias gcm=‘git commit -a -m’

alias gpull=‘git pull’

alias gpush=‘git push’

alias newrepo=‘git init’

git autocorrect

git config --global help.autocorrect 10

resources• https://git-scm.com/doc

• https://try.github.io

• https://www.atlassian.com/git/

• https://training.github.com/kit/downloads/github-git-cheat-sheet.pdf

thank you

@cjb5790