240 likes | 361 Views
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.
E N D
Hands on Git Presented at: Nextbridge LHR C1 Presented by: Muhammad RizwanArshad (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
The Birth of Git • Reliability • Efficient management of large projects • Support for distributed development • Support for non-linear development
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”.
Initialize the GitRepository • cd/path/to/my-git-repo • cd~/Desktop/my-git-repo • gitinit
View the Repository Status • gitstatus #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)
Stage a Snapshot • gitaddindex.html • git status #Changes to be committed: # (use "gitrm --cached <file>..." to unstage) # # new file: index.html
Commit the Snapshot • gitcommit • Saving a version of your project is a two step process: • Staging. Telling Git what files to include in the next commit. • Committing. Recording the staged snapshot with a descriptive message.
View the Repository History • gitlog • commitb650e4bd831aba05fa62d6f6d064e7ca02b5ee1b • Author:unknown <user@computer.(none)> • Date:Wed Jan 11 00:45:10 2012 -0600
Configure Git • gitconfig--globaluser.name"Your Name" • gitconfig--globaluser.emailyour.email@example.com
Basic Commands • gitinit • Create a Git repository in the current folder. • gitstatus • View the status of each file in a repository. • gitadd • <file>Stage a file for the next commit. • gitcommit • Commit the staged files with a descriptive message. • gitlog • View a repository’s commit history. • gitconfig--globaluser.name"<name>“ • Define the author name to be used in all repositories. • gitconfig--global • user.email<email>Define the author email to be used in all repositories.
Undoing Changes • gitlog--oneline 1c310d2Add navigation links 54650a3Create blue and orange pages b650e4bCreate index page
View an Old Revision • gitcheckout54650a3 • gittag-av1.0-m"Stable version of the website“ • Return to Current Version • gitcheckoutmaster • View the Stable Commit • gitcheckoutv1.0 • Undo Uncommitted Changes • gitreset–hard • gitclean-f
Commands: • gitcheckout<commit-id> • View a previous commit. • gittag-a<tag-name>-m"<description>“ • Create an annotated tag pointing to the most recent commit. • gitrevert<commit-id> • Undo the specified commit by applying a new commit. • gitreset--hard • Resettracked files to match the most recent commit. • gitclean-f • Removeuntracked files. • gitreset--hard / gitclean-f • Permanently undo uncommitted changes.
Branches • gitbranch • List all branches. • gitbranch<branch-name> • Create a new branch using the current working directory as its base. • gitcheckout<branch-name> • Make the working directory and the HEAD match the specified branch. • gitmerge<branch-name> • Merge a branch into the checked-out branch. • gitbranch-d<branch-name> • Delete a branch. • gitrm<file> • Remove a file from the working directory (if applicable) and stop tracking the file.
Rebasing • gitrebase<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. • gitrebase-i<new-base> • Perform an interactive rebase and select actions for each commit. • gitcommit--amend • Add staged changes to the most recent commit instead of creating a new one. • gitrebase--continue • Continue a rebase after amending a commit. • gitrebase--abort • Abandon the current interactive rebase and return the repository to its former state. • gitmerge--no-ff<branch-name> • Force a merge commit even if Git could do a fast-forward merge.
Questions ? Suggestions are welcome. Thank you.