Learning Git

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

Starting a project

$ mkdir MyProject
$ cd MyProject
$ git init

OR

Cloning an exiting repo

$ git clone git@github.com:vml-akoebbe/mustached-dubstep.git
Cloning into 'mustached-dubstep'...
remote: Counting objects: 3, done.
remote: Total 3 (delta 0), reused 3 (delta 0)
Receiving objects: 100% (3/3), done.
Checking connectivity... done.

$ ls
mustached-dubstep

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 git@github.com:vml-akoebbe/mustached-dubstep.git

Push Commits to Server

$ git add cssgen.py
$ git commit -m "Added python css generator"
[master 43bd5eb] Added python css generator
 1 file changed, 4 insertions(+)
 create mode 100644 cssgen.py

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 git@github.com:vml-akoebbe/mustached-dubstep.git
 * [new branch]      NewFeature -> NewFeature

Pull Request Examples

Resources

Workflows

Questions?

Made with Slides.com