Tutorial Git Branch

From HaFrWiki42
Jump to navigation Jump to search

Shows the git branch and the git merge commands in detail.
The example is a written example from Version Control with Git [1].


Introduction

A merge unifies two or more commit history branches.
Most often, a merge unites just two branches, although Git supports a merge of three, four, or more branches at the same time.

Preparing for a Merge =

Before you begin a merge, it’s best to tidy up your working directory.
During a normal merge, Git creates new versions of files and places them in your working directory when it is finished.
Furthermore, Git also uses the index to store temporary and intermediate versions of files during the operation.

If you have modified files in your working directory or if you’ve modified the index via git add or git rm, then your repository has a dirty working directory or index.
If you start a merge in a dirty state, Git may be unable to combine the changes from all the branches and from those in your working directory or index in one pass.

Setup

<syntaxhighlight lang="bash"> $ mkdir /Test/gitbranch $ cd /Test/gitbranch $ git init Initialized empty Git repository in /Test/gitbranch/.git/ $ git config user.email "hafr@example.nl" $ git config user.name "Harm Frielink"

$ cat > file Line 1 stuff Line 2 stuff Line 3 stuff ^D

  1. Adding and committing

$ git add file $ git commit -m "Initial 3 line file" [master (root-commit) 4530cfd] Initial 3 lines

1 file changed, 3 insertions(+)
create mode 100644 file
  1. Let's add another file

$ cat > other_file Here is stuff on another file! ^D

  1. Adding and committing

$ git add other_file $ git commit -m "Another file" [master b11d58a] Another file

1 file changed, 1 insertion(+)
create mode 100644 other_file

</syntaxhighlight>

See also

top

Reference

top

  1. Version Control with Git, Powerful Tools and Techniques for Collaborative Software Development, Jon Loeliger & Matthew McCullough, O'Reilly, 2012 Second Edition, isbn=9781449316389