Upload
gary-yeh
View
34
Download
0
Tags:
Embed Size (px)
Citation preview
What is Git?
• Git is a distributed revision control and source code management (SCM) system with an emphasis on speed, data integrity, and support for distributed, nonlinear workflows.
• Git was initially designed and developed by Linus Torvalds for Linux kernel development in 2005, and has since become the most widely adopted version control system for software development.
Git Design Goals
• Speed
• Simple design
• Strong support for thousands of parallel branches
• Fully distributed• full local repository
• offline commits
• full size repository
• Able to handle large projects like Linux kernel effectively
• Ensure integrity
Distributed Development
• Every Git working directory contains the complete repository, history and full revision tracking capabilities
• You’re not dependent on a central server and you don’t have to be online
• Git is extremely fast - much faster than SVN, CVS and other systems
• Revisions (commits) you make to your local repository are available to you only
Distributed Development
• The next time you connect to the internet, push your changes to a remote repository to share them and back them up
• The local nature of Git makes it effortless to create branches to isolate your work
• The local nature of Git makes it possible to coalesce a series of changes (local commits) into a single commit on the remote branch
Understanding of Workflow
• Obtain a repository• git init or git clone
• Make some changes
• Stage your changes• git add
• Commit changes to the local repository• git commit –m “My message”
• Push changes to remote• git push remotename remotebranch
Git Commands
• Setup and Config• git config
• Get and set repository or global options
• git help• Display help information about Git
• Getting and Creating Projects• git init
• Create an empty Git repository or reinitialize an existing one
• git clone• Clone a repository into a new directory
Git Commands
• Basic Snapshotting• git add
• Add file contents to the index
• git status• Show the working tree status
• git commit• Record changes to the repository
Git Commands
• Branching and Merging• git branch
• List, create, or delete branches
• git checkout • Checkout a branch or paths to the working tree
• git merge • Join two or more development histories together
Git Commands
• Sharing and Updating Projects
• git fetch • Download objects and refs from another repository
• git pull• Fetch from and integrate with another repository or a local branch
• git push• Updating remote refs along associated objects
Branching and Merging
• Example1. Develop a website
2. To implement a new function, create a new branch
3. Work on this new branch
C0 C1 C2
master
Branching and Merging
• Example1. Develop a website
2. To implement a new function, create a new branch
3. Work on this new branch
C0 C1 C2
master
iss53
git checkout –b iss53Or
git branch iss53git checkout iss53
Branching and Merging
• Example1. Develop a website
2. To implement a new function, create a new branch
3. Work on this new branch
C0 C1 C2
master
iss53
C3git commit –a –m ‘add a new footer’
Branching and Merging
• There is a bug on the system1. Go to stable released version
2. Create a new branch, and debug
3. After solving the problem, merge the branch
4. Back to the new function branch
C0 C1 C2
master
iss53
C3
Branching and Merging
• There is a bug on the system1. Go to stable released version
2. Create a new branch, and debug
3. After solving the problem, merge the branch
4. Back to the new function branch
C0 C1 C2
master
iss53
C4git checkout –b hotfixgit commit –a –m ‘fixed the problem’
hotfix
C3
Branching and Merging
• There is a bug on the system1. Go to stable released version
2. Create a new branch, and debug
3. After solving the problem, merge the branch
4. Back to the new function branch
C0 C1 C2
iss53
C4git checkout mastergit merge hotfix
hotfix
C3
master
Branching and Merging
• After implement the new function, merge into stable version
C0 C1 C2
iss53
C4git branch –d hotfixgit checkout iss53git commit –a –m ‘finish the new footer ’
C3
master
C5
Branching and Merging
• After implement the new function, merge into stable version
C0 C1 C2
iss53
C4git checkout master git merge iss53
C3
master
C5
C6
Git Implement
• Environment• Windows 7 64-bit
• Git-1.8.4
• Step 1 : Setting user information• Use git bash
git config --global user.name “custom user name"git config --global email “custom e-mail"
Git Implement
• Step 3 : Add files• In git bash, key in
• Step 4 : Version control
git add .git add *
git commit –aorgit commit -m “the information"