ceth
ceth

Reputation: 45325

Git clone --bare / fetch

I have a git repository with long and strange history. I don't know what the developers did with this repository and cannot control what they are doing with it now.

But I need to clone this repository (for redmine integration) and fetch all changes periodically.

What do I do:

git clone --bare [email protected]:/opt/git/repo
cd repo.git
git log

Now I can see all commits. Fine.

Next a developer make a commit in the main repository and I want to fetch all changes (all brances, tags and so on, and so on):

> git fetch --all 
Fetching origin
remote: Counting objects: 18, done.
remote: Compressing objects: 100% (14/14), done.
remote: Total 14 (delta 5), reused 0 (delta 0)
Unpacking objects: 100% (14/14), done.
From git.gmcs.ru:/opt/git/ecco
 * branch            HEAD       -> FETCH_HEAD

But if a ask the commit history I didn't see that last commit which was made in the main repository. Why ?

If I post not enough information I am ready to give you all the needed.

Thanks in advance.

Updated

Here is a brach information in the original repsitory:

git branch -a
  one
  test
* master
  release

Here is a branch information in the cloned repository:

git branch -a
  one
  test
* master
  release

I can see last commits in the master branch of original repository, but can not find them in the master branch of cloned repository.

Upvotes: 10

Views: 7317

Answers (4)

doak
doak

Reputation: 955

To fetch into your bare repository regulary configure first

git config remote.origin.fetch "+*:*"

and then simply run

git fetch --prune

to fetch all changes, including tags, new branches and even branch deletions (option --prune).

  • Please also mind the enclosing double quotation marks (") in the above command to protect the asterix (*) not to be interpreted from your shell.
  • The plus sign is needed to allow non-fastforward updates. That is probably your intention if you want to backup the current state of your remote.
  • Note: Tag deletions are not fetched using this configuration.

See also https://stackoverflow.com/a/33461528/4138912.

Upvotes: 1

Gregor
Gregor

Reputation: 1285

To fetch more updates into a bare repo, I do:

git config remote.origin.fetch 'refs/heads/*:refs/heads/*'

Then I can do:

git fetch

Upvotes: 17

Benjamin Bannier
Benjamin Bannier

Reputation: 58774

You can update the HEAD of your bare repository with git symbolic-ref, e.g. to point it to branch master from remote origin

$ git symbolic-ref HEAD refs/remotes/origin/master

If you use git fetch to update remotes it will update e.g. origin/master. All that was missing was to repoint the clone's HEAD.

Upvotes: 0

cnd
cnd

Reputation: 33784

You should use git pull

or run git merge after fetch to get fetched changes

if you have a bare repository you can not do a pull, because a pull wants to merge with HEAD, which a bare repo does not have.

to update bare repository you can add it as remote to non-bare repository and push to it.

But I think --mirror instead of --bare will work for you as is.

Compared to --bare, --mirror not only maps local branches of the source to local branches of the target, it maps all refs (including remote branches, notes etc.) and sets up a refspec configuration such that all these refs are overwritten by a git remote update in the target repository.

and then you can use git remote update to update mirrored repository

Upvotes: 7

Related Questions