Getting Started on distributed version control with git

Post on 06-May-2015

536 views 3 download

description

Learn how to use git and get accustomed with 15+ most common git commands.

transcript

ANOOP THOMAS MATHEWCTO @ Profoundis Inc.

Getting Started with git

A Little Story

April 2005

Linux Kernel

BitKeeper issue

Linus Torvalds 36% professional developers

@atmb4u

Need for Distributed Version Control

Meet Smarty!

He works as a Software Developer.

@atmb4u

Need for Distributed Version Control

● His job– Create– Save– Edit– Repeat.

● Smarty's friends want to collaborate?

@atmb4u

Need for Distributed Version Control

@atmb4u

git Basics

● Distributed● Collaborative History Tracking● Merge● Flexible● Fast

@atmb4u

git workflow

@atmb4u

git workflow

@atmb4u

1. You MODIFY files in your working directory.

2. You STAGE the files, adding snapshots of them to your staging area.

3. You do a COMMIT, which takes the files as they are in the staging area and stores that snapshot permanently to your git directory.

git Basics

@atmb4u

@atmb4u@atmb4u

git commands

● git config --global user.name "UserName"● git config --global user.email “email@example.com”

git config

@atmb4u@atmb4u

initialize a git repository on current folder

git init

@atmb4u

Retrives the status of the git repository

git status

@atmb4u

● Adds the file to the version control● git add <filename>

git add

@atmb4u

● Commit the added changes to the repo● git commit -m “commit message”

git commit

@atmb4u

● Add a remote server location for the repo● git remote add origin <remote url>● git remote rm origin

git remote

@atmb4u

● Push changes to the destination● git push origin master

remote branch

git push

@atmb4u

● Shows the history of commits of the current branch

git log

@atmb4u

● Shows the difference between two commits in git● git diff 23f4af3 09fb5f2● Writing this to a file gives you a patch

git diff

@atmb4u

● Include all changes specified in a patch file● git apply <patch file>

git apply

@atmb4u

● download new branches and data from a remote repository

git fetch

@atmb4u

● fetch from a remote repo and try to merge into the current branch

● git pull <remote location> <branch>

git pull

@atmb4u

● list, create and manage working contexts● git branch● git branch <branch name>

(create new branch)

git branch

@atmb4u

● switch to a new branch context● git checkout <branch name>● git checkout -b <branch name>

(create branch and checkout)

git checkout

@atmb4u

● merge a branch context into your current one

● git merge

git merge

@atmb4u

Merge conflicts !

@atmb4u

● tag a point in history as important● git tag -a v1.0

git tag

@atmb4u

● remove files from the staging area● git rm <file name>● git rm –cached <file name>

git rm

@atmb4u

● save changes in the current index and working directory for later

● git stash● git stash apply● git stash list● git stash drop

git stash

@atmb4u

● save changes in the current index and working directory for later

● git reset HEAD <file name>● git reset --soft● git reset HEAD --hard

git reset

@atmb4u

● copy a git repository so you can add to it● git clone <remote repo url>

git clone

@atmb4u

● github● Learn a language of choice● Commit once a day

Live Projects

@atmb4u

Code Explorer's Guideto the Open Source Jungle

https://leanpub.com/opensourcebook/

My new Book

@atmb4u

FREE

● @atmb4u● We are looking for interns.

Thank You !

@atmb4u