Git why how when and more

26
Git . Why, How, and more @gargrag | [email protected]

description

Intermediate introduction to git workflow, good practices some commands and useful tools.

Transcript of Git why how when and more

Page 1: Git   why how when and more

Git .Why, How, and more

@gargrag | [email protected]

Page 2: Git   why how when and more

PM -> track workingPM -> control the teamPM -> interact with the process.PM -> know wich issues is the team working on.

DEV -> co-workDEV -> rollbackDEV -> manipulate changesDEV -> parallel versions

SUP -> know what code is deployedSUP -> see which are the latest changesSUP -> pull request some easy issues

Why Git ?

Page 3: Git   why how when and more

● remotes● commits● tags● branches● local / remote

Basic explanation

Page 4: Git   why how when and more

Good practices .keep calm and take control

Page 5: Git   why how when and more

Commit often

Git can control only the code you commit, so commit early and often, that's the way to have your code under

control and backed up.

Page 6: Git   why how when and more

Be reversible

Make commits atomically, use all the git potencial, to make commits clear, by feature and reversible.

Git has all you need to commit changes grouped by each, fix/feature you code.

Page 7: Git   why how when and more

Make clear and useful commit msgs

Besides making reversible, and atomic commits, ship they with descriptive messages, so other teammates can know exactly what each commit is about (especially under stress)

Page 8: Git   why how when and more

Divide and conquer

If your code goes too large, divide it in repos by modules or something depending on the software architecture you are on.

You can use either submodules or separate repositories.

Page 9: Git   why how when and more

Get updated

Pull often, and before start working.

Page 10: Git   why how when and more

Remember your workflow

We have defined a workflow, remember it, and act accord.

Page 11: Git   why how when and more

Be ware of changing public history

Git allows you to change the published history, but it can be an annoyance for your teammates.

Better, fix the things by doing commits, maybe by revert, or patching, etc. But going forward.

Page 12: Git   why how when and more

Don't freak

All your code is under control, any change is rollback-able, any non - recursive merge, can be done with ease.

keep calm, things can look nasty, but belive me, is simple.

Page 13: Git   why how when and more

Use a custom prompt

Use a custom unix prompt, that shows you info about the repo you are working with, the branch you are, the status and more things.

export PS1='[\u@\h \W$(__git_ps1 " (%s)")]\$ '

git has some ps1 variables and functions you can set up, and if you prefer something more sophisticated take a look at:

● https://github.com/nojhan/liquidprompt● https://github.com/bpinto/oh-my-fish

Page 14: Git   why how when and more

Maintain your repo

Do some maintenance, sure someone has versioned a mysql dump, and your repo is growing insanely. Take

care of that, and maintain the repo often.

Repack, delete weight files, and put order.

Page 15: Git   why how when and more

Rtfm!and take some practice.

● http://pcottle.github.io/learnGitBranching/● http://git-scm.com/book/ch3-4.html● https://www.codeschool.com/courses/try-git● https://confluence.atlassian.com/display/BITBUCKET/Bitbucket+101

Page 16: Git   why how when and more

Basic commandsand not only basic.

Page 17: Git   why how when and more

Get started

git clone [dest_dir] Clone a reopsitory

git init Initializes a new repo

Page 18: Git   why how when and more

Where we are

git remote show will show all your remotes

git remote show origin show information for remote named origin

git remote add [name] [url] add a remote named [name] with url [url]

git remote rm [name] removes a remote named [name]

git status show git status

git status -sb summarized status

git branch show list of local branches

git branch --all show list of local and remote branches

git fetch fetch a remote origin/branch

git checkout [-b new_branch] checks out to a existing branch, or new branch if -b is used

Page 19: Git   why how when and more

Commiting

git add add files to the commit

git add -p to add partial files

git add --all to add deleted files

git rm remove a tracked file

git rm --cached remove only the file track

git commit makes a commit

git commit -m "message" creates a commit with the spec. message

git commit -am "message" add all tracked files and commit with the message

git commit --ammend if you forgot to add something to the last commit

git reset

Page 20: Git   why how when and more

What is happening

git status

git log shows you the git log

git log --graph --abbrev-commit --decorate --date=relative --format=format:'%C(bold blue)%h%C(reset) - %C(bold green)(%ar)%C(reset) %C(white)%s%C(reset) %C(dim white)- %an%C(reset)%C(bold yellow)%d%C(reset)' --all

Pretty log !

git diff

git whatchanged file

git blame file

Page 21: Git   why how when and more

Git pull, git push

git pull origin master pulls branch master from remote origin to local branch master

git push bitbucket master:dev git pushes the local branch dev to remote branch master at origin bitbucket

Page 22: Git   why how when and more

Git pull, git push

git pull origin master pulls branch master from remote origin to local branch master

git push bitbucket master:dev git pushes the local branch dev to remote branch master at origin bitbucket

Page 23: Git   why how when and more

Git stash (get ride of your local changes)

git stash stashes your local changes

git stash list show stashes

git stash apply | pop <stash> re - apply a stash

git stash drop <stash> deletes a stash

git stash branch <stash>

Read More at http://git-scm.com/docs/git-stash

Page 24: Git   why how when and more

Git merge

Page 25: Git   why how when and more

Others● Rebase http://git-scm.com/book/en/Git-Branching-Rebasing● Revert ● cherry-pick

Useful Tools & Resources● TIG -> http://jonas.nitro.dk/tig/● Meld -> http://meldmerge.org/● SourceTree ->http://www.sourcetreeapp.com/● Git Cola -> http://git-cola.github.io/● GitX -> http://gitx.frim.nl/● StupidGit -> https://github.com/gyim/stupidgit● GitHowTo -> http://githowto.com/● Tower CheatSheet

Page 26: Git   why how when and more

?>End