Beruflich Dokumente
Kultur Dokumente
Chase Maupin
Agenda
• What is Git
• Configuring Git
• Creating a local repository
• Cloning a remote repository
• Checking Repository Status
• Making Changes
• Viewing History
• Working with branches
• Merging Basics
• Rebasing
• Rewriting History
• Creating Patches
• Pushing Changes
• References
What is Git?
Public Branch
Local Branch
Dev D
Configuring Git
User Information
General Setup
E-mail Setup
User Information
Why?
How?
Why?
Protocols
Why Clone
Protocols
What is a Commit?
Adding Files to a Commit
Removing Files from a Commit
Removing Files
Moving Files
What is a Commit?
Why Branch?
Making a Branch
Listing Branches
Switching Between Branches
Why Branch?
• Branches allow you to group a series of
commits together
– For example you can have a branch for each
development project
• You can switch between branches to keep
you work isolated
– The changes in one branch are contained to that
branch only unless you merge them into another
branch
• Branches can share all of the repository data
they have in copy, not multiple copies
• This way one repository can look like several
copies but you only have to manage one
Making a Branch
• To make a branch of your current branch and switch
to the new branch do:
host$ git checkout -b <new branch>
• Or you can do this the long way
host$ git branch <new branch>
host$ git checkout <new branch>
• To make a branch from a specific commit
host$ git branch <new branch> <commit id>
• To make a branch from a named commit (i.e. another
branch)
host$ git branch <new branch> <other branch>
– NOTE: This will make the branch from the commit that
<other branch> is pointing to at this time. It will not track
changes to the other branch (see later sections)
Listing Branches
What is a Merge?
How do I merge?
Dealing with Conflicts
What is a Merge?
What is Rebasing?
Interactive Rebasing
Rebasing vs. Merging
What is Rebasing?
• Rebasing alters where a sequence of commits are based
• Commonly used to
– Keep commits on a development branch up-to date with another branch
(i.e. master)
– Relocate a branch
– Reorder, remove, combine, or change commits
• Commits after a rebase have different commit ids
– Thus the change is the same but the commit is new
Updating A Branch Relocate A Branch
A B C A B C
D E F D E F
G H
A B C G’ H’
A B C
D’ E’ F’
D E F
Interactive Rebasing
• By using the -i option to rebase you can enter
interactive mode
• Interactive mode allows you to change the commits
with:
– reordering commits = Just change their order in the list
– removing commits = Just remove the commit entry from the
list
– reword = Change the commit message
– edit = stop the rebase process so you can amend a commit
– squash = combine a commit with the previous commit
– fixup = like squash but discards the commit’s log message
• Often used to clean up a series of commits before
making patches for submission or pushing changes
Rebasing vs. Merging
• Rebasing makes new commit ids unlike
merging
• Old commits that have been removed
(stranded are gone)
– Anyone based off these commits can also
become stranded
• Anything relying on these commit ids will be
confused by the rebase
– i.e. other branches or other clones of a repository
• Rebasing is usually used on local branches
and repositories
• Once a branch or repository is shared
merging should be used
Rewriting History
Amending Commits
Reordering Commits
Editing Commits
Squashing Commits
Removing Commits
Amending Commits
What is a Patch?
Specifying the Patch Set
Patch Options
Sending Patches
What is a Patch?