Slide 1

Slide 1 text

Brian O'Connor Open Networking Lab 2/11/2015 Working with

Slide 2

Slide 2 text

What this talk will cover Git Basics - Getting started - Basic workflow and commands GitHub - Getting started - Anatomy of a project - How to contribute

Slide 3

Slide 3 text

Disclaimer This will be a bit of a whirlwind tour, and I will borrow some of the materials from git-scm.com and github.com There are plenty of in-depth (and better) tutorials and videos that get into a lot of the details that I may gloss over.

Slide 4

Slide 4 text

Why Version Control? ● For Version History ○ Allows you to go back and revert changes and recover or compare against old version ○ Makes experimentation easier (using branches) ● To Facilitate Collaboration ○ Allows you to make modifications to files in parallel as a team and merge the result

Slide 5

Slide 5 text

What is Git? vs. CVS, Subversion, Perforce Git, Mercurial, Bazaar

Slide 6

Slide 6 text

How do I start? ● A brand new project ○ git init # in the project's top level directory ● An existing project (more common) ○ git clone [URL] ○ git clone https://github.com/mininet/mininet.git Note: Projects will contain a .git directory that will track will contain all changes and metadata. Also, if you don't have git installed, do this first: https://help.github.com/articles/set-up-git/

Slide 7

Slide 7 text

Branching ● master ○ default branch when you check out a project ○ usually "stable" and "deployable" ● topic branches ○ best practice for changes ○ local only, unless you push them somewhere git checkout -b my-feature master # to create git checkout master # to switch branches

Slide 8

Slide 8 text

Committing Changes 1. Make a change to a file 2. Look at what's changed (optional) ○ git status 3. Stage your files for commit ○ git add [file name] 4. Commit! ○ git commit # opens the default editor Shortcut: git commit -a -m"Commit Message"

Slide 9

Slide 9 text

Anatomy of a commit commit ea9ae214f9bca97537378f205910d62b7aa4be47 tree de130618eaf06592df72b43b06e88ea87160d8b6 parent 0cc189e6814cb0bf5af049fd6074212a2599a571 Author: Brian O'Connor Date: Fri Feb 6 16:41:49 2015 -0800 Using CommandSession console instead of System.* in AbstractShellCommand print and error fixes ONOS-986 diff --git a/cli/src/main/java/org/onosproject/cli/AbstractShellCommand.java b/cli/src/main/java/org/onosproject/cli/AbstractShellCommand.java index e6a62d0..b404db6 100644 --- a/cli/src/main/java/org/onosproject/cli/AbstractShellCommand.java +++ b/cli/src/main/java/org/onosproject/cli/AbstractShellCommand.java @@ -62,7 +62,7 @@ public abstract class AbstractShellCommand extends OsgiCommandSupport { * @param args arguments */ public void print(String format, Object... args) { - System.out.println(String.format(format, args)); + session.getConsole().println(String.format(format, args)); } /** commit hash (SHA1) author information commit message commit diff git show [commit hash | branch | HEAD]

Slide 10

Slide 10 text

Looking at the past git log [branch | commit hash] git log --oneline --graph --decorate=short * 0094997 (tag: 2.2.0b3) fixing install-mininet-vm.sh * 7a411b6 Merge pull request #453 from cdburkard/master |\ | * c2341cd update examples README with new examples |/ * 4219b22 (tag: 2.2.0b2) 2.2.0b2 * 08ab7e8 Merge pull request #452 from mininet/nat-cmd |\ | * ab97dfa (origin/nat-cmd, nat-cmd) fixing no --nat issue | * af1ccf9 Updating NAT class to use gateway interface * | 3ef6bcf Additional info about --nat and LinuxRouter |/ * 015cd9e Merge pull request #443 from cdburkard/devel/cluster |\ | * bbf94cd use rcmd instead of quietRun when shutting down remote nodes * | 3d44bcd MiniNet -> Mininet * | 1817cbc Pass pyflakes * | e0bf8ec Minor code cleanup

Slide 11

Slide 11 text

: the social network for code

Slide 12

Slide 12 text

Getting Started on GitHub ● Create an Account ● Add your public key (strongly recommended) ○ makes pushing changes easier Get started @ https://github.com/

Slide 13

Slide 13 text

Anatomy of a project page repository viewer commit log project forks issue tracker pending contributions project wiki download URL

Slide 14

Slide 14 text

Pulling the latest changes ● git clone [URL] ○ create a new repository with the latest code ● git pull [remote] [branch] ○ gets the latest code for the specified branch on the remote and merges it into your current local branch ● git fetch [remote] ○ updates your local metadata with the latest information about the remote repository

Slide 15

Slide 15 text

Dealing with merge conflicts ● Happens when two people change the same file in a conflicting way ○ Usually manifest themselves when you do git pull ● What you'll see ○ CONFLICT (modify/delete): ... # Automatic merge failed; fix conflicts and then commit the result. ● How to fix it ○ Update the offending file(s) ○ Stage the changes using git add [filename] ○ Commit using git commit

Slide 16

Slide 16 text

Forking a project ● Your own copy of someone else's project ● Somewhere to push your local changes ○ And collaborate with others on them, too! ● Push your changes to GitHub ○ git push origin [branch name] ● To fork, click the "Fork" button on the upstream project page in GitHub ○ Creates a clone of the upstream in GitHub

Slide 17

Slide 17 text

Keeping your fork up to date ● Set up remote ○ git remote add upstream [upstream URL] 1. Fetch the latest from the remote ○ git fetch upstream 2. Checkout your local master ○ git checkout master 3. Merge the upstream changes ○ git merge upstream/master 4. Push the changes to GitHub ○ git push origin master

Slide 18

Slide 18 text

Pull requests ● Push the latest changes to your topic branch to GitHub ○ git push origin [branch] ● Click the "Compare & pull request" button on your fork's project page:

Slide 19

Slide 19 text

Issue tracking and GitHub wiki ● Automatically built-in ● Issue tracker ○ Useful for reporting bugs, tracking new features, etc. ○ Automatically integrated using commit messages e.g. "Closes #843" ● Wiki ○ Great place to put project documentation e.g. installation instructions, tutorials, etc. ○ Editable by anyone with a GitHub account ○ Versioned

Slide 20

Slide 20 text

Live Demo ● Fork a project ● Make a change and commit ● Pull and Merge conflicts ● Push to remote ● Create a pull request

Slide 21

Slide 21 text

Other Topics ● .gitignore file ○ Tells git to ignore certain files or patterns, like build artifacts ● git stash ○ Useful for quickly stashing local changes while pulling/updating code ● git rebase ○ Replay your branch from a new parent ○ NEVER rebase code that's been pushed* ○ Used heavily in Gerrit workflow

Slide 22

Slide 22 text

Merge vs. Rebase Note: NEVER rebase public (i.e. pushed to remote) branches Exception: Okay to rebase pending changes/commits in Gerrit Images from: https://www.atlassian.com/git/tutorials/merging-vs-rebasing/workflow-walkthrough git merge master git rebase master Feature Branch

Slide 23

Slide 23 text

Resources Cheat Sheet https://training.github.com/kit/downloads/github-git-cheat-sheet.pdf Collection of Tutorials https://help.github.com/articles/good-resources-for-learning-git-and- github/ Fantastic (free!) eBook http://git-scm.com/book/en/v2 Tons more easily found via Google