Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8883913
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T20:56:04+00:00 2026-06-14T20:56:04+00:00

I’m trying to use libgit2 to first clone a bare repository and later on

  • 0

I’m trying to use libgit2 to first clone a bare repository and later on to update it with changes from a github origin. The cloning works fine:

git_repository *_repository
git_clone_bare(&_repository, REPOSITORY_URL, path, &transferProgressCallback, NULL);
git_repository_free(_repository);

But when I try to update the repository from origin libgit2 always downloads the entire repository again. It just doesn’t fetch the changes only. I’m using this code:

git_remote *remote;
git_repository *_repository;

git_repository_open(&_repository, path);
git_remote_load(&remote, _repository, "origin");
git_remote_connect(remote, GIT_DIR_FETCH);
git_remote_download(remote, &transferProgressCallback, NULL);

git_remote_disconnect(remote);
git_remote_update_tips(remote);
git_remote_free(remote);

(I removed the error handling.) I use a callback like this to report the progress:

void transferProgressCallback(const git_transfer_progress *stats, void *payload) {
    float receivedMegaBytes = (float)stats->received_bytes/(1024*1024.0);
    float progress = ((float)stats->received_objects / (float)stats->total_objects) * 100.0;
    printf("Loading: %.1f (%.1f)\n", progress, receivedMegaBytes);
}

According to the callback everything is downloaded (same number of bytes as with git_clone_bare). I must be missing something or doing something wrong, right? But I don’t see where. All I want is that the code fetches changes only (that is stuff not present locally). But instead it keeps fetching all of the entire repository.

Please, what could be the problem here? Thank you very much in advance!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T20:56:05+00:00Added an answer on June 14, 2026 at 8:56 pm

    That’s very weird. I cannot reproduce the issue.

    Which version of libgit2 are you running against?

    I’ve locally added a test to the libgit2 fetch suite which reproduces your issue and… it passes against the current latest development tip of libgit2. The following urls were successfully checked:

    • http://github.com/libgit2/libgit2.git
    • http://github.com/libgit2/TestGitRepository.git
    • https://github.com/libgit2/libgit2.git
    • https://github.com/libgit2/TestGitRepository.git
    static void transferProgressCallback(const git_transfer_progress *stats, void *payload)
    {
        bool *invoked = (bool *)payload;
        *invoked = true;
    }
    
    void test_network_fetch__doesnt_retreive_a_pack_when_the_repository_is_up_to_date(void)
    {
        git_repository *_repository;
        git_remote *remote;
        bool invoked = false;
    
        cl_git_pass(git_clone_bare(&_repository, "https://github.com/libgit2/TestGitRepository.git", "./fetch/lg2", NULL, NULL));
        git_repository_free(_repository);
    
        cl_git_pass(git_repository_open(&_repository, "./fetch/lg2"));
    
        cl_git_pass(git_remote_load(&remote, _repository, "origin"));
        cl_git_pass(git_remote_connect(remote, GIT_DIR_FETCH));
    
        cl_assert_equal_i(false, invoked);
    
        cl_git_pass(git_remote_download(remote, &transferProgressCallback, &invoked));
    
        cl_assert_equal_i(false, invoked);
    
        cl_git_pass(git_remote_update_tips(remote));
        git_remote_disconnect(remote);
    
        git_remote_free(remote);
        git_repository_free(_repository);
    }
    

    UPDATE:

    I’ve sent a pull request to the libgit2 project in order to make sure the test also pass on Travis, the CI server.

    • The pull request
    • The PR build log
    • The result of the specific test

    UPDATE 2:

    Ok, I’ve done some more troubleshooting and I still can’t reproduce the issue.

    • I’ve create a new repository on GitHub, through the web interface
    • Through a bash session, I’ve created a commit, then pushed it upstream
    • I then cloned it through libgit2 in a new temporary folder. 3 objects were downloaded
    • I then fetched it again, nothing was downloaded.
    • Back to the bash session, I’ve created another commit and pushed it upstream
    • Back to the libgit2 code, fetching again downloads the 3 new objects from the second commit.

    The code below, even if this is not a real test (as it requires some interaction from the user), demonstrates what is explained above.

    void test_network_fetch__retrieve_a_pack_when_the_remote_repository_has_been_updated(void)
    {
        git_repository *_repository;
        git_remote *remote;
        bool invoked = false;
    
        /*
         * $ mkdir /tmp/so-check/ && cd /tmp/so-check/
         * 
         * $ touch README.md
         * 
         * $ git init
         * Initialized empty Git repository in d:/temp/so-check/.git/
         * 
         * $ git add README.md
         * 
         * $ git commit -m "first commit"
         * [master (root-commit) e3454be] first commit
         *  0 files changed
         *  create mode 100644 README.md
         * 
         * $ git remote add origin https://github.com/nulltoken/so-check.git
         * 
         * $ git push -u origin master
         * Username for 'https://github.com': nulltoken
         * Password for 'https://nulltoken@github.com':
         * Counting objects: 3, done.
         * Writing objects: 100% (3/3), 212 bytes, done.
         * Total 3 (delta 0), reused 0 (delta 0)
         * To https://github.com/nulltoken/so-check.git
         *  * [new branch]      master -> master
         * Branch master set up to track remote branch master from origin.
         * 
         * $
         */
    
        cl_git_pass(git_clone_bare(&_repository, "https://github.com/nulltoken/so-check.git", "./fetch/soc", NULL, NULL));
        git_repository_free(_repository);
    
        cl_git_pass(git_repository_open(&_repository, "./fetch/soc"));
    
        cl_git_pass(git_remote_load(&remote, _repository, "origin"));
        cl_git_pass(git_remote_connect(remote, GIT_DIR_FETCH));
    
        cl_assert_equal_i(false, invoked);
    
        cl_git_pass(git_remote_download(remote, &transferProgressCallback, &invoked));
    
        cl_assert_equal_i(false, invoked);
    
        cl_git_pass(git_remote_update_tips(remote));
        git_remote_disconnect(remote);
    
        git_remote_free(remote);
        git_repository_free(_repository);
    
        /*
         * $ mkdir /tmp/so-check2 && cd /tmp/so-check2
         * 
         * $ git clone https://github.com/nulltoken/so-check.git .
         * Cloning into '.'...
         * remote: Counting objects: 3, done.
         * remote: Total 3 (delta 0), reused 3 (delta 0)
         * Unpacking objects: 100% (3/3), done.
         *
         * $ echo "Test" > README.md
         * 
         * $ git add README.md
         * 
         * $ git commit -m "Now with a meaningful content"
         * [master 9c6c300] Now with a meaningful content
         *  1 file changed, 1 insertion(+)
         *
         $ git push
         * Username for 'https://github.com': nulltoken
         * Password for 'https://nulltoken@github.com':
         * Counting objects: 5, done.
         * Writing objects: 100% (3/3), 262 bytes, done.
         * Total 3 (delta 0), reused 0 (delta 0)
         * To https://github.com/nulltoken/so-check.git
         *    e3454be..9794f71  master -> master
         * $
         */
    
        /* Set a breakpoint below in order to push the additional commit.
         * Once it's done, let the code run again.
         */
        cl_git_pass(git_repository_open(&_repository, "./fetch/soc"));
    
        cl_git_pass(git_remote_load(&remote, _repository, "origin"));
        cl_git_pass(git_remote_connect(remote, GIT_DIR_FETCH));
    
        cl_assert_equal_i(false, invoked);
    
        cl_git_pass(git_remote_download(remote, &transferProgressCallback, &invoked));
    
        cl_assert_equal_i(true, invoked);
    
        cl_git_pass(git_remote_update_tips(remote));
        git_remote_disconnect(remote);
    
        git_remote_free(remote);
        git_repository_free(_repository);
    }

    Below the output of the console, resulting of the second download. One can note that only 3 objects are being retrieved:

    Fetching: (0/3)
    Fetching: (1/3)
    Fetching: (2/3)
    Fetching: (3/3)
    Fetching: (3/3)
    

    And the repository holds 6 objects (3 from the first commit, 3 from the second one):

    $ git count-objects --verbose
    count: 6
    size: 0
    in-pack: 0
    packs: 0
    size-pack: 0
    prune-packable: 0
    garbage: 0
    

    From my perspective, it looks like libgit2 is indeed able to download a differential pack.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I am currently running into a problem where an element is coming back from
I am trying to render a haml file in a javascript response like so:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.