being dangerous with git

25
BEING DANGEROUS WITH GIT BY YOUR GEEK FRIEND: /

Upload: gediminas-morkevicius

Post on 15-Jul-2015

574 views

Category:

Technology


0 download

TRANSCRIPT

BEING DANGEROUS WITHGIT

BY YOUR GEEK FRIEND: /

WHO IS THIS DUDE?PHP, C, Go - programming language fanaticopen-source geek, Arch linux, DWM, ViM userAuthor of And I share my stuff

WHY YOU SHOULD CONSIDER USINGGIT

git is decentralizedgit is small and fastgit does not store changes - it stores snapshotsgit has a staging areagit is a new standard?

WORKFLOWGit does not force any workflow, use what works best for

your team and project, even if you are working alone, git willfit perfectly well.

WHAT MAY BE USEFUL TO KNOWABOUT GIT REPOSITORY

Here is a fresh repository guts:$ lsHEADbranchesconfigdescriptionhooksindexinfoobjectsrefs

WHEN TO USE REBASE OR MERGEUse to cleanup, prepare and keep up to date your

topic branches.

rebased topic branches or hotfixes

HOW TO PREVENT THIS FROMHAPPENING?

git log --pretty=oneline --abbrev-commit

rebase your feature branches

EXAMPLE:mkdir ~/project && cd ~/projectgit inittouch LICENSEgit add LICENSEgit commit -am 'initial commit - set license'git remote add origin https://github.com/user/project.gitgit checkout -b feature/project-bootstrap

After a while...

Do you want this to go into production stream?

LETS REBASEInteractively rebase 5 commits from HEAD

git rebase --interactive HEAD~5

At this point we can choose what to do with commits.Rebase will rewind the chosen number of commits and

modify them accordingly to prefered changes.

Initially rebase will stop to rename the first commit, werename it properly:

Next, rebase will stop on "boostrap project" wich will havetwo commits squashed

Now if we had pushed our commits to git repository in anybranch name, we could reference these commits with their

hashes. This way it could look like:

Since we haven't, we can just leave those as extra commitmessages

Finally, it will stop to rename "add feature x" commit, it is notclear what feature we have added, lets fix it as well:

When we save and close it, rebase will finish

And instead of...

We have:

Which history log do you choose to see in production?

Before merging it back to master - make sure you are up todate

git fetchgit rebase origin/master

There are cases, when you may want to split a commit,consider a situation:

So what we should do ? - git rebase -i HEAD~4

Set for commit, which we want to split

Rebase will rewind, pick the commit for edit and pause. Nowlets reset one commit from the current HEAD

git reset HEAD~

Lets see what we have in :git status

Add the first commit, which includes doctrine2 orm. We willuse so we stage only a specific change.git add --patch composer.json

Hit to edit hunk

Now save and close it. We should have only needed changesstaged.

git commit -m 'include doctrine2 orm into project'

Next, we have a front controller integration:git add src/MyApp/FrontController.php public/*git commit -m 'create front controller'

Further more, lets commit phpunitgit add phpunit.xml.dist tests

And again patch a composer.json change:git add -p composer.json

Hit to edit hunk

Now save and close it. We should have only needed changesstaged.

git commit -m 'bootstrap phpunit tests'

And finally we have only behat stuff left.git add features composer.jsongit commit -m 'bootstrap behat mink functional tests'git rebase --continue

Thats it! Now we have:

Have fun and be hardcore! And ...

Do not be afraid of rebase, experiment on your branches,keep branch backups if needed.