Managing code with Git and Stash

Quick Poll

  • Who is using a VCS for their code?
  • Who is using a centralized VCS (svn, cvs, etc)?
  • Who is using a DVCS (git, hg, bazar)?
  • Who is using GitHub or Bitbucket?

Why Version Control?

Why should I care about version control?

  • Develop collaboratively
  • Central location of all code
  • Infinite history/undo
  • Sandbox big changes
  • Development log
  • Tagging specific points
  • Compare versions 

Centralize vs Decentralized

Centralized (SVN)

  • Server-based (required)
  • Network connection needed to checkout, commit, revert, branch, etc.
  • Operations can be slow based on server and connection speed
  • All commits, branches and tags are public

Decentralized (Git)

  • Client based (you have the entire repo on your machine)
    • No server is needed to use git locally
  • Committing will only commit to you local cloned/init'd repo
  • Branching and tagging happens locally
  • Changes are "pushed" to the server in a separate step
  • Stash incomplete changes and apply any time
  • Pull changes from a server or other users
  • Multiple remote repositories

Management Server

  • Stash, GitHub, Bitbucket, etc.
  • Custom Workflows for team projects
  • Fork a repo
  • Pull requests using remotely accessible repository
    • Review code before merging in to blessed branch
    • Commenting
  • User Roles

Git Basics

Local only demo

Starting a project

$ cd existing-project
$ git init
$ git add --all
$ git commit -m "Initial Commit"
$ git remote add origin ssh://git@jiraapps2:7999/~abk/git-pres.git
$ git push origin master

OR

Cloning an exiting repo

$ git clone ssh://git@jiraapps2:7999/~abk/git-pres.git
Cloning into 'git-pres'...
remote: Counting objects: 3, done.
remote: Total 3 (delta 0), reused 3 (delta 0)
Receiving objects: 100% (3/3), done.
Checking connectivity... done.

$ ls
git-pres

Commit Some Code

$ git push origin master
Counting objects: 4, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 456 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To ssh://git@jiraapps2:7999/~abk/git-pres.git

Push Commits to Server

$ git init
Initialized empty Git repository in /Users/abk/Projects/git-presentation/.git/
$ git add MyCoolFile.php
$ git commit -m "Added my first file"
[master (root-commit) 0b3486d] Added my first file
 1 file changed, 3 insertions(+)
 create mode 100644 MyCoolFile.php

Branching

$ git branch NewFeature
$ git branch
  NewFeature
* master
$ git checkout NewFeature
Switched to branch 'NewFeature'

Commit and Push to a Branch

$ git commit -a -m "Added a new line"
[NewFeature e5a4c95] Added a new line
 1 file changed, 1 insertion(+)

$ git push origin NewFeature
Counting objects: 9, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 315 bytes | 0 bytes/s, done.
Total 3 (delta 1), reused 0 (delta 0)
To ssh://git@jiraapps2:7999/~abk/git-pres.git
 * [new branch]      NewFeature -> NewFeature

Centralized Git with Stash

Demo

  • Existing Code
  • New Project

Resources

Workflows

Questions?

Managing code with Git and Stash

By akoebbe

Managing code with Git and Stash

  • 1,861