Git. all meaningful operations can be expressed in terms of the rebase command. -Linus Torvalds, 2015

Similar documents
Git. A Distributed Version Control System. Carlos García Campos

git commit --amend git rebase <base> git reflog git checkout -b Create and check out a new branch named <branch>. Drop the -b

Submitting your Work using GIT

Versioning with git. Moritz August Git/Bash/Python-Course for MPE. Moritz August Versioning with Git

CESSDA Expert Seminar 13 & 14 September 2016 Prague, Czech Republic

GUIDE TO MAKE A REAL CONTRIBUTION TO AN OPEN SOURCE PROJECT 1. 1

git-flow Documentation

Git Workflows. Sylvain Bouveret, Grégory Mounié, Matthieu Moy

Outline The three W s Overview of gits structure Using git Final stuff. Git. A fast distributed revision control system

What is git? Distributed Version Control System (VCS); Created by Linus Torvalds, to help with Linux development;

Git. A fast distributed revision control system. Nils Moschüring PhD Student (LMU)

Common Git Commands. Git Crash Course. Teon Banek April 7, Teon Banek (TakeLab) Common Git Commands TakeLab 1 / 18

CS 390 Software Engineering Lecture 5 More Git

Version Control: Gitting Started

Software Development I

Introduction to distributed version control with git

Laboratorio di Programmazione. Prof. Marco Bertini

Fundamentals of Git 1

Git, the magical version control

a handful of Git workflows for the agilist steven harman twitter: stevenharman

Git for Subversion users

Git. Presenter: Haotao (Eric) Lai Contact:

Using Git For Development. Shantanu Pavgi, UAB IT Research Computing

Creating a Patch. Created by Carl Heymann on 2010 Sep 14 1

Gitting things done. Hands-on introduction to git niceties. Jan Urbański Ducksboard

How to be a git. Dominic Mitchell

Git Like You Mean it. Alan Ott SCaLE 16x March 8-11, 2018

Git. Ľubomír Prda. IT4Innovations.

Why? Clean Model Branches Local reflog Flows Doc Ex. Advanced use of Git. Matthieu Moy

Version Control with GIT

What is version control? (discuss) Who has used version control? Favorite VCS? Uses of version control (read)

2 Initialize a git repository on your machine, add a README file, commit and push

Git Workbook. Self-Study Guide to Git. Lorna Mitchell. This book is for sale at

CPSC 491. Lecture 19 & 20: Source Code Version Control. VCS = Version Control Software SCM = Source Code Management

Version Control for Fun and Profit

Git Tutorial. André Sailer. ILD Technical Meeting April 24, 2017 CERN-EP-LCD. ILD Technical Meeting, Apr 24, 2017 A. Sailer: Git Tutorial 1/36

Best Practices. Joaquim Rocha IT-DSS-TD

Using GitHub to Share with SparkFun a

Introduction, Instructions and Conventions

git Version: 2.0b Merge combines trees, and checks out the result Pull does a fetch, then a merge If you only can remember one command:

Revision control Advanced git

Why? Clean Model Branches Local reflog Flows Doc Ex. Advanced use of Git. Matthieu Moy

KTH Royal Institute of Technology SEMINAR 2-29 March Simone Stefani -

Github/Git Primer. Tyler Hague

Git Introduction CS 400. February 11, 2018

FAQ Q: Where/in which branch do I create new code/modify existing code? A: Q: How do I commit new changes? A:

Tutorial: Getting Started with Git. Introduction to version control Benefits of using Git Basic commands Workflow

An introduction to git

book In partnership with:

About SJTUG. SJTU *nix User Group SJTU Joyful Techie User Group

Source Code Management wih git

Mike McQuaid INCLUDES 66 TECHNIQUES. Foreword by Scott Chacon MANNING

August 22, New Views on your History with git replace. Christian Couder

Using git to download and update BOUT++

Version control with Git.

Git(Lab) Tutorial and Hands-On

The Old World. Have you ever had to collaborate on a project by

Lab 08. Command Line and Git

Introduction to Git. Database Systems DataLab, CS, NTHU Spring, 2018

INET

How to git with proper etiquette

b. Developing multiple versions of a software project in parallel

VCS VERSION CONTROL SYSTEMS

Lecture 6 Remotes. Sign in on the attendance sheet!

Git - A brief overview

Git Branching. Chapter What a Branch Is

Advanced Git. Luc Sarzyniec. Xilopix, February / 88

Introduction to Supercomputing

Index. Alias syntax, 31 Author and commit attributes, 334

Introduction to Version Control

Git for Newbies. ComMouse Dongyue Studio

Version Control with Git

1. Git. Robert Snapp

Git Guide. Meher Krishna Patel. Created on : Octorber, 2017 Last updated : October, More documents are freely available at PythonDSP

Midterm Next Week. Last year s midterm (which didn t include remotes):

Git for Version Control

Git GitHub & secrets

IC Documentation. Release 0.1. IC team

A L A TEX-oriented intro to Git

an introduction to git

Algorithm Engineering

GIT for companies Mark Struberg, INSO TU Vienna

Topics covered. Introduction to Git Git workflows Git key concepts Hands on session Branching models. Git 2

AVOIDING THE GIT OF DESPAIR

Distributed Version Control (with Git)

Git. Christoph Matthies Software Engineering II WS 2018/19. Enterprise Platform and Integration Concepts group

Version Control. Collaborating with git. Tim Frasier

GIT. CS 490MT/5555, Spring 2017, Yongjie Zheng

Version Control. So#ware Quality Quality Audit and Cer2fica2on. Master in Computer Engineering. Roberto García

Git and GitHub. Dan Wysocki. February 12, Dan Wysocki Git and GitHub February 12, / 48

Git Resolve Conflict Using Mine Command Line

Revision Control. An Introduction Using Git 1/15

Section 1: Tools. Contents CS162. January 19, Make More details about Make Git Commands to know... 3

Θερινό Σχολείο, Ιουλίου git. Αχιλλέας Πιπινέλης. Μονάδα Αριστείας ΕΛ/ΛΑΚ ΤΕΙ Αθήνας

Agenda. - Final Project Info. - All things Git. - Make sure to come to lab for Python next week

CS 520: VCS and Git. Intermediate Topics Ben Kushigian

Version Control System - Git. zswu

Assumptions. GIT Commands. OS Commands

API RI. Application Programming Interface Reference Implementation. Policies and Procedures Discussion

CSE 391 Lecture 9. Version control with Git

Transcription:

Git all meaningful operations can be expressed in terms of the rebase command -Linus Torvalds, 2015 a talk by alum Ross Schlaikjer for the GNU/Linux Users Group

Sound familiar? add commit diff init clone log push pull status branch merge

Git only know a handful of tricks Once you know them, it s quite simple Command names don t give away what they do But it all sorta make sense if you know internals (and the internals are good. Linus is just not an interface designer)

Getting Started git init git clone

Lets make a repository

Getting stuff done git add git commit

Getting stuff done ross@beast:/h/r/demo$ echo 'Hello git!' tee foo Hello git! ross@beast:/h/r/demo$ git add foo git add writes to the repository. Creates a binary object

Getting stuff done ross@beast:/h/r/demo$ git commit -m Commitment Add wrote to the repo, commit does not Commit: - Creates a commit object with an ID - Adds labels to it

You ve just seen 80% of git

Let s add again ross@beast:/h/r/demo$ echo 'Hello once more' tee -a foo Hello once more ross@beast:/h/r/demo$ git add foo Adds a new copy of foo to the repo Doesn t move the labels

And commit ross@beast:/h/r/demo$ git commit -m Second commit! Creates another commit object Move the labels That s it!

Branching Branching is super easy! What happens if we do: ross@beast:/h/r/demo$ git branch feature?

Branching Branching is super easy! What happens if we do: ross@beast:/h/r/demo$ git branch feature We add another label That s it!

Checkout Checking out code changes which label moves when I commit ross@beast:/h/r/demo$ git checkout feature

Checkout Checking out code changes which label moves when I commit ross@beast:/h/r/demo$ git checkout feature Committing will now move feature, not master

Branching So let s add a new file ross@beast:/h/r/demo$ echo New branch tee bar ross@beast:/h/r/demo$ git add bar

Branching So let s add a new file ross@beast:/h/r/demo$ echo New branch tee bar ross@beast:/h/r/demo$ git add bar And commit ross@beast:/h/r/demo$ git commit -m cool feature That s branching!

Staging Area aka Index aka Cache

Staging area When you add, git writes to a staging area Commit commits the data in the staging area Allows you to build up commits

Let s talk IDs

Git IDs are SHA1sums - What s a checksum - Git SHAs contain: content (files), author, date, log message, previous commit - Every ID is unique - Every commit is unique - Commits never change

Typical git workflow branch feature checkout feature edit test add commit merge master test checkout master merge feature

Typical git workflow (simpler) Isolate Work Update Share

Merge Feature is complete! Demo$ git checkout master Demo$ git merge feature Updating 7cef3ce..e48af8d Fast-forward bar 1 + 1 file changed, 1 insertion(+) create mode 100644 bar Special case: fast forward

Merge (fast-forward) Demo$ git merge feature Updating 7cef3ce..e48af8d Fast-forward bar 1 + 1 file changed, 1 insertion(+) create mode 100644 bar It s all in a line, just move the label!

What if it s not simple? What if we change master? Demo$ git checkout master Demo$ echo Time for something new > foo Demo$ git add foo

What if it s not simple? What if we change master? Demo$ git checkout master Demo$ echo Time for something new > foo Demo$ git add foo

What if it s not simple? What if we change master? Demo$ git checkout master Demo$ echo Time for something new > foo Demo$ git add foo And commit: Demo$ git commit -m Change comes from within

So now let s merge Demo$ git merge feature --asks for a commit message-merge made by the 'recursive' strategy. bar 1 + 1 file changed, 1 insertion(+) create mode 100644 bar Merge commits have two parents!

Disaster strikes Turns out I didn t want to do that

Reset Demo$ git reset --hard HEAD^ Reset moves labels around (--hard means checkout after moving) Commit ID e still exists you can go back

Playing well with others push fetch pull

Playing well with others push fetch pull This is where the trouble starts

Remotes For sharing, you need to know where Demo$ mkdir../remote Demo$ git init --bare../remote Demo$ git remote add origin../remote Git doesn t care how it gets at the remote (http, SSH, filesystem, git protocol)

So let s share Demo$ git push origin master Remote Local

So let s share git push origin master Remote Local

git push Like most git ops, works on current branch Can do funky things // Push local branch feature to remote branch master Demo$ git push origin feature:master // Push nothing to remote branch feature (aka delete feature) Demo$ git push origin :feature

Wait, what s that? When you talk to master, git takes note of where it thinks things are

remote branch vs. remote/branch remote/branch = local label (ref) remote branch = the branch, on remote diff, log, etc. want refs push wants to to know the remote and branch

tags Label, just like everything else. Git is just the same trick over and over! Tags cannot move, however

Going along as normal Demo$ git checkout master Demo$ echo Totally bug fee line of code >> foo Demo$ git commit -am Everything is fine

Everything is not fine Demo$ git checkout master Demo$ echo Totally bug fee line of code >> foo Demo$ git commit -am Everything is fine I made an error in code I already committed! I guess I ll just fix it and commit again Demo$ sed -i.bak s/fee/free/g foo Demo$ git commit -am Typo fix Demo$ git push

Rebase

Rebase Often described as rewrites history But history is immutable! It really creates a whole new history.

Let s rebase Demo$ git rebase -i HEAD^^

Let s rebase Demo$ git rebase -i HEAD^^

Squashing (Other rebase operations are available)

What does this mean for DAG? f: Introduce error g: bugfix commit

What does this mean for DAG? f: Introduce error g: Bugfix commit -- rebase -h: Squashed commit

Cool, glad we sorted that Demo$ git push To../Remote/! [rejected] master -> master (non-fast-forward) error: failed to push some refs to '../Remote/' What have we wrought

What went wrong? git push origin master? Remote Local

NEVER rebase pushed code This is how you make enemies

NEVER rebase pushed code This is how you make enemies

Fetch Pull refs (labels) from a remote Find out what others have done

Pull Pull = fetch + merge (by default) If you re lucky, it s a fast-forward If you have more than one developer, it s not (and that s bad)

Word of caution Merging many branches all the time is a mess

How to avoid? Git pull will merge by default But there s another behaviour...

How to avoid? Git pull will merge by default But there s another behaviour ~ rebase ~

The situation: You are working on a branch Someone else works on that branch, or master They push, changing either master or branch - You can t just push (You re behind!) - You don t want to merge (It s messy!)

The Situation:

The solution If the branch I am working on changed: Demo$ git pull --rebase (which is sugar for) Demo$ git fetch --all Demo$ git rebase origin/branch If the branch I am branched off of changed: Demo$ git rebase master

What does this look like?

That s the big secret Rebase = the clean history you hear about

One last thing: reflog Or, How to recover from anything Git keeps track of all commits it s seen lately Even if they are no longer referenced 52263d9 HEAD@{4}: refs/heads/master 52263d9 HEAD@{5}: 96fd397 HEAD@{6}: 4db0413 HEAD@{7}: rebase -i (finish): returning to rebase -i (squash): Everything is fine rebase -i (start): checkout HEAD^^ commit: Typo fix

That s all folks Questions? Comments? Obscenities?