24
Hands on Git Presented at: Nextbridge LHR C1 Presented by: Muhammad Rizwan Arshad (PSE) VTeams March 07, 2013

Hands on Git

Embed Size (px)

DESCRIPTION

Hands on Git. Presented at: Nextbridge LHR C1 Presented by: Muhammad Rizwan Arshad (PSE) VTeams March 07, 2013. Introduction. Git is a version control system Created for a single task Managing changes to your files Track every change a software project. Files and Folders. - PowerPoint PPT Presentation

Citation preview

Page 1: Hands on  Git

Hands on Git

Presented at:Nextbridge LHR C1

Presented by:Muhammad Rizwan Arshad

(PSE) VTeams

March 07, 2013

Page 2: Hands on  Git

Introduction

Git is a version control systemCreated for a single taskManaging changes to your filesTrack every change a software project

Page 3: Hands on  Git

Files and Folders

Page 4: Hands on  Git

Local VCS

Page 5: Hands on  Git

Centralized VCS

Page 6: Hands on  Git

Distributed VCS

Page 7: Hands on  Git

The Birth of Git

ReliabilityEfficient management of large projectsSupport for distributed developmentSupport for non-linear development

Page 8: Hands on  Git

Installation

For Windows users, this will install a special command shell called Git Bash.

OS X and Linux users can access Git from a normal shell.

To test your installation, open a new command prompt and run ”git –version”.

Page 9: Hands on  Git

Initialize the Git Repository

cd /path/to/my-git-repocd ~/Desktop/my-git-repogit init

Page 10: Hands on  Git

View the Repository Statusgit status

# On branch master # # Initial commit # # Untracked files: # (use "git add <file>..." to include in what will be committed) # # index.html nothing added to commit but untracked files present (use "git add" to track)

Page 11: Hands on  Git

Stage a Snapshot

git add index.html git status

# Changes to be committed: # (use "git rm --cached <file>..." to unstage) # # new file: index.html

Page 12: Hands on  Git

Commit the Snapshotgit commitSaving a version of your project is a two step

process:1. Staging. Telling Git what files to include in

the next commit.2. Committing. Recording the staged snapshot

with a descriptive message.

Page 13: Hands on  Git

View the Repository History

git logo commit

b650e4bd831aba05fa62d6f6d064e7ca02b5ee1b

o Author: unknown <user@computer.(none)> o Date: Wed Jan 11 00:45:10 2012 -0600

Page 14: Hands on  Git

Configure Git

git config --global user.name "Your Name" git config --global user.email

[email protected]

Page 15: Hands on  Git

Status output vs. Log output

Page 16: Hands on  Git

The fundamental Git workflow

Page 17: Hands on  Git

Basic Commands git init

Create a Git repository in the current folder. git status

View the status of each file in a repository. git add 

<file>Stage a file for the next commit. git commit

Commit the staged files with a descriptive message. git log

View a repository’s commit history. git config --global user.name "<name>“

Define the author name to be used in all repositories. git config --global 

user.email <email>Define the author email to be used in all repositories.

Page 18: Hands on  Git

Undoing Changes

git log --oneline1c310d2 Add navigation links 54650a3 Create blue and orange pages b650e4b Create index page

Page 19: Hands on  Git

View an Old Revisiongit checkout 54650a3git tag -a v1.0 -m "Stable version of the

website“Return to Current Version

git checkout masterView the Stable Commit

git checkout v1.0Undo Uncommitted Changes

git reset –hardgit clean -f

Page 20: Hands on  Git

Resetting vs. Reverting

Page 21: Hands on  Git

Commands:git checkout <commit-id>

View a previous commit.git tag -a <tag-name> -m "<description>“

Create an annotated tag pointing to the most recent commit.

git revert <commit-id>Undo the specified commit by applying a new commit.

git reset --hardReset tracked files to match the most recent commit.

git clean -fRemove untracked files.

git reset --hard / git clean -fPermanently undo uncommitted changes.

Page 22: Hands on  Git

Branchesgit branch

List all branches.git branch <branch-name>

Create a new branch using the current working directory as its base.git checkout <branch-name>

Make the working directory and the HEAD match the specified branch.

git merge <branch-name>Merge a branch into the checked-out branch.

git branch -d <branch-name>Delete a branch.

git rm <file>Remove a file from the working directory (if applicable) and stop

tracking the file.

Page 23: Hands on  Git

Rebasinggit rebase <new-base>

Move the current branch’s commits to the tip of <new-base>, which can be either a branch name or a commit ID.

git rebase -i <new-base> Perform an interactive rebase and select actions for each commit.

git commit --amend Add staged changes to the most recent commit instead of creating a

new one.git rebase --continue

Continue a rebase after amending a commit.git rebase --abort

Abandon the current interactive rebase and return the repository to its former state.

git merge --no-ff <branch-name> Force a merge commit even if Git could do a fast-forward merge.

Page 24: Hands on  Git

Questions ?Suggestions are welcome.

Thank you.