Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git-merge with repository on local filesystem

For some context: I just upgraded Ubuntu which broke my existing gitosis installation (see here: bug #368895), and have just reinstalled gitosis from packages. I now want to migrate my whole config and set of repositories from the old gitosis installation (which still exists and can be pulled from but is otherwise broken).

I now have two gitosis-admin directories locally, one for each gitosis installation. One has a full history, the other's is empty. I want to pull across this history. Here's what's happening though:

me@server:~/gitosis-admin-new$ git merge ../gitosis-admin-old/
fatal: '../gitosis-admin-old/' does not point to a commit

... where there is are git repositories in ~/gitosis-admin-old/ and ~/gitosis-admin-new/

I'm probably going to need to do this for the other repositories too, which have much longer and more important histories, so copying and committing as one is not an option.

What am I doing wrong? I've tried pointing to .git/HEAD which as I understand is a commit, but that doesn't work. Could someone explain how to do this? Thanks!

like image 681
Ben Hymers Avatar asked Oct 30 '09 19:10

Ben Hymers


People also ask

Can remote repository be local file system?

The main purpose of a remote repository is to place the repository to a central location so that it can be accessed by multiple developers. A remote repository can be accessed via http, ssh or even local (file-system) protocols.

Why you should rebase instead of merge?

The Rebase Option But, instead of using a merge commit, rebasing re-writes the project history by creating brand new commits for each commit in the original branch. The major benefit of rebasing is that you get a much cleaner project history. First, it eliminates the unnecessary merge commits required by git merge .

How do I merge one branch to another locally?

Merging Branches in a Local Repository To merge branches locally, use git checkout to switch to the branch you want to merge into. This branch is typically the main branch. Next, use git merge and specify the name of the other branch to bring into this branch.


2 Answers

You need to use git pull with repository, not git merge (which is for branches):

git pull ../gitosis-admin-old/

You might need to select a branch in remote to merge, e.g.:

git pull ../gitosis-admin-old/ master

If you need to do this merge only once, then using git remote add like in jamessan answer is unnecessary work. On the other hand if you would be revisiting the remote (pulling more than one time), this solution would be better than using git pull <location> <branch>.

like image 157
Jakub Narębski Avatar answered Oct 18 '22 17:10

Jakub Narębski


You need to create a remote for that repository and then fetch & merge (or simply pull) from there.

git remote add admin-old file://$HOME/gitosis-admin-old
git pull admin-old
like image 44
jamessan Avatar answered Oct 18 '22 18:10

jamessan