Git and Github workshop

Preview:

Citation preview

Workshop

Git and Github for beginners(and something for advanced too)

Otto Kekäläinen Startup.bg 6.11.2015

Sofia, Bulagaria

@ottokekalainen

● 15+ years in open source● technology & business & advocacy● development with git since 2010

The MariaDB FoundationContinuity and open collaboration

● MariaDB.org sponsors include MariaDB.com, Booking.com, Automattic, Odin/Parallels, Visma...

● Employs 6 persons, including ”Monty” Widenius, the creator of MySQL/MariaDB

● Single contact point for collaboration and contributions● The Foundation makes sure all pull requests and patches are

reviewed● All development work done with git at github.com/mariadb

Outline1. The story of Git2. Basic commands3. Doing it with Github4. Git internals5. Advanced commands6. Git everywhere?

1. Story of Git

Git / t/ɡɪ”A silly, incompetent, stupid, annoying or childish person.”

http://en.wiktionary.org/wiki/git

"I'm an egotistical bastard, so I name all my projects after myself.

First Linux, now Git”

Linus Torvalds, PC World. 2012-07-14

Linus needed a new source code revision manager for Linux, and none of the available options in 2005 where

good enough, so he wrote his own in.

Kernel 2.6.12 was the first release managed by Git and version 1.0 of Git was released in December 2005.

Design goals of Git:● distributed revision management● protection against corruption,

both accidental and hostile● speed

Git popularity according to OpenHub.net

Git popularity according to Google Trends

git

svn

...but adoption would be faster if it was not so difficult to use.

Originally Linus did not intend end users to use Git directly, instead he tried to delegate to somebody else the task of making the actual command line

interface. We are still waiting for it...

Luckily Git has been simplified and documentation has improved over time, but some Git commands

still refer to Git internals that are difficult to grasp.

E.g. git-push: Update remote refs along with associated objects.

Git might feel difficult at first, but once you learn it, you never want to go back to anything less

flexible and powerful.

Install on Linux:apt-get install git git-gui

Install on Mac/Windows: git-scm.com/downloads

2. Basic commands

First obstacle: same terms with different meanings

git config --global user.name "John Doe"git config --global user.email johndoe@example.com

Define the author of commits

git initgit add example.txtgit commit -am “First commit”# edit filesgit commit -am “Second commit”

Start a new repository

git pull# edit filesgit commit -am “Implemented X”git push

git loggit show

Typical workflow

3. Doing it with Github

Visit http://try.github.com/

After making your first repository, set up SSH keyfor convenient authentication:

https://help.github.com/articles/generating-ssh-keys

Note: Github is not the only Git hosting site,Gitlab and Bitbucket are popular too.

Exercise:- go to https://github.com/ottok/git-training and fork it- look at the fork under your own Github account and clone it to your laptop- edit names.txt and add yours- push changes back to Github- in Github, do a merge request back to me

git clone git://github.com/<yourname>/git-training.git

# edit names.txtgit commit -am “Added my name”git push# Open pull request on Github

The best part of Github is pull requests, and how they enable

frictionless collaboration among millions of developers

4. Git internals

Folder /.git contains everything,your / is just the working copy.

Folder /.git contains everything,your / is just the working copy.

When you commit a 2 MB file /example.png,your / will grow to 4 MB...

When you add a file,it goes to the staging area.

The file does not go into theactual history tree until the stage

is committed.

Commands push and pull and many other commandsare shortcuts that act with both

your local repository and the remote repositories.

Image credits Steve Bennet (http://steveko.wordpress.com/2012/02/24/10-things-i-hate-about-git/)

Git tracks content, not files!

Git history is immutable as each commit ID is the SHA-1 of the commit data and metadata (including the commit ID of parents). Changing any commit in the history will change the SHA-1 commit IDs of every following commit in the chain.

If you need to change something in the history, you have to rebase and make a new history.

Git commit IDs and rebaseOriginal 'git log --oneline':1bf7024 MDEV-8991: bind-address appears twice in default my.cnfb2205c5 MDEV-9011: Redo log encryption does not workcf9e6b2 Fix test failures seen on buildbot.923827e MDEV-7949: Item_field::used_tables() takes 0.29% in OLTP RO239e0c5 MDEV-8551 compilation fails with 10.1.6

After 'git rebase -i HEAD^^^':34350b9 MDEV-8991: bind-address appears twice in default my.cnff5f2dd9 MDEV-9011: Redo log encryption does not work531e1ac Fixed all bugs923827e MDEV-7949: Item_field::used_tables() takes 0.29% in OLTP RO239e0c5 MDEV-8551 compilation fails with 10.1.6

Branches and tags

Basically just labels that point to certain commit IDs.Each commit ID point to its parent, thus forms a chain.

How to write a good commit message

● Your attitude towards commit messages should be the same as for code: it is written once, but read thousands of times.

● Don't explain how was done, that is visible in the diff anyway. Explain what the intention was and why it was made.

● Use imperative form “Fix typo” (instead of “Fixed typo”)● Keep subject line short and sweet, under 72 chars. Body can be verbose. ● Use proper English. Capital letters. Reference issue identifiers is possible.● Looking for a good example? How about one by Linus himself?

https://github.com/torvalds/linux/commit/fc90888

5. Advanced commands

Sorry, but default commands not very friendly, so get yourself good cheat cheets and write up your common

commands once you've figured them out..

Image credits Steve Bennet (http://steveko.wordpress.com/2012/02/24/10-things-i-hate-about-git/)

Example of how fast-forward works 1/2

● Branch “feature-branch-example” forked from master branch “10.1” and has 3 commits

Example of how fast-forward works 2/2

● Normal merge defaults to fast-forward in this case●

● Result of no fast-forward (git merge --no-ff)

Want to avoid “ugly” merge commits?

● git config pull.ff=only● git config alias.ff=merge --ff-only● Run 'git rebase master' to rebase you work on the master

branch before pushing or making pull request● Run 'git merge' on when importing changes from remote

head only if you really want to merge

Want to put a simple shared repository on any SSH capable server? Create a bare .git with no working files:

git init --bare

Want to have notifications when somebody commits?Put a shell script at .git/hooks/post-receive

6. Git everywhere?

Would you like to store all your files in Git?Git-annex

Diff of binary files?Add in .git/config

[diff "odf"] textconv=odt2txt

See also: http://www-verimag.imag.fr/~moy/opendocument/

Bug tracker as part of project?http://bugseverywhere.org/

Bug tracker and wiki contents in Git?trac+git

Clone wiki from Github withgit clone https://github.com/YOUR_USERNAME/YOUR_REPOSITORY.wiki.git

Publish to the web with one commit?self-hosted Jekyll or

on Github https://pages.github.com/

Open source alternative to Dropbox based on Git?http://sparkleshare.org/

Would you like others to contribute to your software?

Provide easy forking (git clone), easy way to develop new feature (git branch),

and an easy way to send them back (merge request).

Will Git credits replace developers CV's?

Is there anything we can't store and track in Git?

© 2015 MariaDB Foundation51

Thanks!

mariadb.org

@ottokekalainenotto@mariadb.org

Recommended