first steps with git - linux day 2016 - enna

21
Francesco Pira | fpira.com First steps with Git Francesco Pira fpira.com @pirafrank [email protected] Linux Day 2016 - Enna (Sicily)

Upload: francesco-pira

Post on 15-Apr-2017

109 views

Category:

Technology


2 download

TRANSCRIPT

Page 1: First steps with Git - Linux Day 2016 - Enna

Francesco Pira | fpira.com

First steps with Git

Francesco Pira

fpira.com

@pirafrank

[email protected]

Linux Day 2016 - Enna (Sicily)

Page 2: First steps with Git - Linux Day 2016 - Enna

Francesco Pira | fpira.com

Who am I?

• Web developer

• btw currently sys admin

• I like Python

• I’ve founded a startup (no much fuss...)

• I write a blog in my spare time

• ...and some code (github.com/pirafrank)

• I like business

• ...but code is better!

Page 3: First steps with Git - Linux Day 2016 - Enna

Francesco Pira | fpira.com

What is a VCS?

• VCS stands for Version Control System

• A software to handle different versions of a pool of files

• Great to manage source code

• Something you need to get a job

• Something you need to share your weekend project

• Something you need to deploy and maintain your blog• See Github Pages, GitLab Pages and Jekyll

Page 4: First steps with Git - Linux Day 2016 - Enna

Francesco Pira | fpira.com

Why VCS?

• A repository as a unique codebase

• Reliability

• History and changes + easy to roll back at any point

• Blaming (who changed what?)

• Side projects (aka forking a repo)

• Parallel development on the same repo (aka team working)

• Code deployment!

Page 5: First steps with Git - Linux Day 2016 - Enna

Francesco Pira | fpira.com

Popular VCS software

● Git

● Team Foundation Server (MS)

● Apache Subversion (SVN)

● Mercurial (BitBucket)

● Bazaar (Canonical)* In order of popularity

Page 6: First steps with Git - Linux Day 2016 - Enna

Francesco Pira | fpira.com

• repository = a directory with files (usually code!)• working tree = index of files part of the repo• ignoring = no to keep track of changes• staging = virtual area with changes ready to commit• commit = snapshot of a repository, changes saved in history• head = pointer to the latest commit of the current branch• branch = a copy of files to track different changes• merging = merging the history of a branch with his parent one• conflict = 2 or more people making changes to same file• tag = named pointer to a particular snapshot (e.g. v1.1.0)• remote = server (it can be another PC for distributed VCS)

VCS concepts

Page 7: First steps with Git - Linux Day 2016 - Enna

Francesco Pira | fpira.com

Who’s Git?

• Created by Linus Torvalds (mid 2005)

• to manage the shared development of Linux kernel

• Today is the most common VCS

• It works using snapshots, pointers and compressed deltas

• All changes and history are in ./.git

• Works best with small files (see git lfs)

• Distribute (remote) architecture

• Used by GitHub: the biggest and de facto standard platform

for sharing open-source code

Page 8: First steps with Git - Linux Day 2016 - Enna

Francesco Pira | fpira.com

Setup the environment

● Download and install git

○ bit.ly/linux-day-git-install

● Set it up

○ git config --global user.name "My Name"

○ git config --global user.email "[email protected]"

● Remotes require your to have an RSA key: set it up!

○ ssh-keygen -t rsa -b 4096 -C "[email protected]"

○ eval "$(ssh-agent -s)"

○ ssh-add ~/.ssh/id_rsa

Pro tip: Use different RSA keys (personal, work, etc.)

Page 9: First steps with Git - Linux Day 2016 - Enna

Francesco Pira | fpira.com

Your first commit, yay!

Locally on your computer

• git init

• git add .

• git remote add origin ...

• git commit -m “Hey! This is my first commit”

• git push origin master

Your teammate

• git clone ...

Page 10: First steps with Git - Linux Day 2016 - Enna

Francesco Pira | fpira.com

Some notes

master is the main and first branchorigin is the primary remote. You push your code to it

Tip: Use --global to make a setting work for all repo of current local user

Interesting: Git global configuration usually lives here ~/.gitconfig or here ~/.config/git/config

Page 11: First steps with Git - Linux Day 2016 - Enna

Francesco Pira | fpira.com

Live demo

Page 12: First steps with Git - Linux Day 2016 - Enna

Francesco Pira | fpira.com

• init = initialise the repository (make ./.git subdir)• clone = make a local copy of the repo from a remote one• diff = show current changes (before staging them)• add = stage one of more file / folders• commit = make a ‘snapshot’ / save a state• branch = create a branch off the current one• merge = merge a branch into his parent• fetch = download (new) changes from remote• pull = fetch from remote branch + merge to local one• checkout = switch branch / restore file in working tree• reset = undo / remove from staging area• log = explore changes history• … tons of commands, each one has tons of parameters: RTFM!

Main Git commands

Page 13: First steps with Git - Linux Day 2016 - Enna

Francesco Pira | fpira.com

Lazy as a pig? Aliases!

git config --global alias.co checkout

git config --global alias.br branch

git config --global alias.ci commit

git config --global alias.st 'status -s'

git config --global alias.unstage 'reset HEAD --'

...Make yours!

Page 14: First steps with Git - Linux Day 2016 - Enna

Francesco Pira | fpira.com

Best practices

• Don’t zip repositories! Use remotes!

• master as the main branch

• devel as the main development branch

• all features start off devel

• all features ends

• usually you don’t push features

• all releases must be tagged (in master)

• use semantic versioning for tags

• hotfix start off master, merged to master and devel

Page 15: First steps with Git - Linux Day 2016 - Enna

Francesco Pira | fpira.comCredits to Vincent Driessen

Page 16: First steps with Git - Linux Day 2016 - Enna

Francesco Pira | fpira.com

Live demo

Page 17: First steps with Git - Linux Day 2016 - Enna

Francesco Pira | fpira.com

UI clients

● Windows and macOS

○ Sourcetree

● Linux

○ SmartGit

Page 18: First steps with Git - Linux Day 2016 - Enna

Francesco Pira | fpira.com

Best platforms

● GitHub

○ Free only for open-source public projects

● BitBucket

○ Free for unlimited private or public repos (any license)

○ Paid for 5+ collaborators

● GitLab

○ Paid enterprise version (with support)

○ Free Community Edition (self-hosted)

○ Free gitlab.com: unlimited repos, unlimited collaborators

Page 19: First steps with Git - Linux Day 2016 - Enna

Francesco Pira | fpira.com

Your turn!

• Wow! git log --graph --oneline --decorate --all

• Discover git stash and git pop

• Deploy best practices

• Use git-flow

• Deploy a web application using git

• Try git-lfs

• ...Have fun!

Page 21: First steps with Git - Linux Day 2016 - Enna

Francesco Pira | fpira.com

Thank you!Keep in touch

fpira.com

@pirafrank

[email protected]

github.com/ pirafrank