avp::ptr weblog

Everything that is in our mind.

Archive for the ‘branch’ tag

Git: How to copy a range of commits from one branch to another?

with 4 comments

Sometimes it is useful to copy a series of commit to another branch. This post describes how to do this using git rebase. Two example illustrate different scenarios which should help to understand the command arguments in generell.

Example 1: The commit P, Q, R which are contained in branch feature should be copied to branch master. The commits should be appended to commit M.

git rebase --onto M O R && git rebase HEAD master

The first command git rebase --onto M O R copies the commits P, Q, R to the branch master. They won’t be visible if you check the visual graph in gitk. This is because there is no branch reference that points to one of the three commits. To update the branch master run the second command git rebase HEAD master which moves up the HEAD to commit R.

Read the rest of this entry »

Written by tobi

September 28th, 2012 at 11:45 pm

Posted in Uncategorized

Tagged with , , , ,

How to create an independent branch in git?

without comments

While working with a version control system like git it is sometimes a good idea to create an independent branch. This article shows how to accomplish that. In this example I want to hold onto the documentation in a separate branch.
I assume, that you already created a repository and added various commits onto you master branch.

Prepare your ignore list
Now its time to prepare for the repository. First, edit your .gitignore file and exclude the doc/ folder which you will be creating in the next step.

Create an orphan branch
Create a new independent branch with the git checkout option --orphan. The option is available since Git 1.7.2. Initially, you will have to remove the files that have been created in the working directory, but right after the branch is independent.
Now you can create a doc/ folder and create documentation files. In the end you can commit them to the repository as usual.

git checkout --orphan documentation
git rm -rf .
mkdir doc
cd doc
// Do work.
// git add your files to the doc/ folder
git commit -m "Added documentation files."

Checkout the master branch
To checkout the master branch while still being able to list the documentation files do the following.

git checkout master && git merge --no-commit documentation
git reset master

The files added to the documentation branch earlier will appear in the working directory visible to the master branch. Thanks to the .gitgnore file they will not be listed as untracked files.

The initial discussion on an unrelated branch can be found on stackoverflow.com. Thanks to hillutcovo and phord for their input!

Written by tobi

October 9th, 2011 at 5:16 pm

Posted in Uncategorized

Tagged with , , ,

Colored bash prompt showing git branch (.bash_rc)

without comments

Written by tobi

March 11th, 2011 at 3:31 am

Posted in Uncategorized

Tagged with , , , , , ,