top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

Combining two branches in GIT

+1 vote
224 views

While experimenting with using Git as a backup tool (by automatically snapshotting my home directory), I've generated a long branch which is a series of commits that record states of my home directory.

Actually, I've got *two* such branches.

It would be very convenient if I could assemble the two series of commits in time-order to form one branch that covers the total time interval. I figure there is a 10% chance that there is some Git tool that happens to make this really easy, and so I should ask before I write a script to do the job manually.

posted May 19, 2013 by anonymous

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

0 votes

perimenting with using Git as a backup tool (by automatically snapshotting my home directory), Ive generated a long branch which is a series of commits that record states of my home directory.

Actually, Ive got *two* such branches. It would be very convenient if I could assemble the two series of commits in time-order to form one branch that covers the total time interval. I figure there is a 10% chance that there is some Git tool that happens to make this really easy, and so I should ask before I write a script to do the job manually.

I think you have 2 ways just a simple merge go to your final branch (named branch1)

git checkout branch1    
- next, merge

git merge branch2
then, continue using branch1...

or use rebase if you want track all comits
http://git-scm.com/book/ch3-6.html 
answer May 19, 2013 by anonymous
Similar Questions
+1 vote

I have a large Git project which I would like to dissect into subprojects with their own repositories. Git subtrees are ideal for this task: I first

  • create a branch with the contents of only one subfoldergit subtree split -P -b

and then

  • pull this branch into another repository.

For a transitional phase, I would like to have the subprojects read-only and sync them from master. The question is how to organize this. For every commit to master, I could of course perform the above procedure repeatedly for all subprojects, but this seems less then ideal since it does all the work all over again.

Is there a way to merge master into the subtree branches?

+2 votes

One practice of using git to have one feature per branch.

Let's say a developer has worked on many small features in many branches. Then he sends one pull request to the central (not controlled by him) for each feature he has developed. While he is waiting for all the features be merged into the central repository, he needs to use all these feature locally.

To do so, he may need to merge the changes in these branches to his local master branch. But this can be tedious when he has many branches.

Is there a way to somehow setup a branch so whenever something is committed to the branch, the changes will also be simultaneously committed to the local master branch? By this way, the develop can avoid having to merge changes from many branches.

+2 votes

I tend to accumulate lots of branches as I'd do one branch per feature. When cleaning up, I'd like to
delete all branches, which have been merged.

I could use

 $ git branch -d (which was merged already?) ^C
 $ git branch --merged # let's find out
 ...
 $ # Now run git branch -d with each of the branches.

This kind of question has already been discussed,
http://stackoverflow.com/questions/6127328/how-can-i-delete-all-git-branches-which-are-already-merged
suggests: git branch --merged | grep -v "*" | xargs -n 1 git branch -d

I could think of:

 $ git branch -d --merged # no need to specifiy a branch iff --merged is given with -d
 $ git branch --delete-merged # comes as an new extra option, doesn't clutter other commands
 $ git branch -d keyword-for-all-merged-branches

Before starting such a feature, I'd like to hear input of others.

+1 vote

At some point I added a large file into a git repository. It now exists on multiple branches, possibly with some changes to it. I'd like to remove it from git, but leave its current form (say the one on the master branch) on the file system.

I tried (on a dummy git archive)

git filter-branch --index-filter 'git rm --cached --ignore-unmatch bigfile' master branch1 branch2

That, however, does not leave a copy of bigfile on the file system.It isn't clear to me why not, though the description of the --tree-filteroption to filter-branch (I'm using the --index-filter option, but is is "similar") states:" (new files are auto-added, disappeared files are auto-removed ... )".
Is there a direct way to do what I want, with git? I've found similar requests;none of the responses point out that the above command actually deletes the file from the file system.

...