Successfully reported this slideshow.

First steps with Git - Linux Day 2016 - Enna

1

Share

Loading in …3
×
1 of 21
1 of 21

First steps with Git - Linux Day 2016 - Enna

1

Share

Download to read offline

Slides of my talk at Linux Day 2016 in Enna.
Content: What is a VCS (Version Control System), VCS concepts, Introduction to Git, first commands and best practises.

Slides of my talk at Linux Day 2016 in Enna.
Content: What is a VCS (Version Control System), VCS concepts, Introduction to Git, first commands and best practises.

More Related Content

Related Books

Free with a 14 day trial from Scribd

See all

First steps with Git - Linux Day 2016 - Enna

  1. 1. Francesco Pira | fpira.com First steps with Git Francesco Pira fpira.com @pirafrank me@fpira.com Linux Day 2016 - Enna (Sicily)
  2. 2. 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!
  3. 3. 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
  4. 4. 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!
  5. 5. Francesco Pira | fpira.com Popular VCS software ● Git ● Team Foundation Server (MS) ● Apache Subversion (SVN) ● Mercurial (BitBucket) ● Bazaar (Canonical) * In order of popularity
  6. 6. 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
  7. 7. 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
  8. 8. 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 "my@email.com" ● Remotes require your to have an RSA key: set it up! ○ ssh-keygen -t rsa -b 4096 -C "my@email.com" ○ eval "$(ssh-agent -s)" ○ ssh-add ~/.ssh/id_rsa Pro tip: Use different RSA keys (personal, work, etc.)
  9. 9. 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 ...
  10. 10. Francesco Pira | fpira.com Some notes master is the main and first branch origin 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
  11. 11. Francesco Pira | fpira.com Live demo
  12. 12. 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
  13. 13. 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!
  14. 14. 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
  15. 15. Francesco Pira | fpira.com Credits to Vincent Driessen
  16. 16. Francesco Pira | fpira.com Live demo
  17. 17. Francesco Pira | fpira.com UI clients ● Windows and macOS ○ Sourcetree ● Linux ○ SmartGit
  18. 18. 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
  19. 19. 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!
  20. 20. Francesco Pira | fpira.com Sources and extras • https://git-scm.com/book/en/v2/Getting-Started-Git-Basics • https://help.github.com/articles/generating-a-new-ssh-key-and-addi ng-it-to-the-ssh-agent/ • https://www.atlassian.com/git/tutorials • http://nvie.com/posts/a-successful-git-branching-model/ • http://semver.org (semantic versioning)
  21. 21. Francesco Pira | fpira.com Thank you! Keep in touch fpira.com @pirafrank me@fpira.com github.com/ pirafrank

×