You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello all,
I am working on some Git related service and I want to push to remote repo, which happens to be clone of local repo on filesystem. But when try to push from clone to remote(basically on local file system) I end up with following error.
Error: local push doesn't (yet) support pushing to non-bare repos.; class=Invalid (3); code=BareRepo (-8)
Explanation
May be following sequence diagram will help to clarify what I am trying to achieve. The reason we are creating clone of repo, is because we are developing tool to work with multiple repos, so we don't want to spoil anything in main repo and we perform all required operation in clones repo and once everything is complete without error just push the changes to remote branch.
Sample code
use std::path::PathBuf;use anyhow::{Context,Result};use git2::{Cred,PushOptions,RemoteCallbacks,Repository};fnpush_branch(repo:&Repository,branch:&str) -> Result<()>{let private_key = PathBuf::from("/Users/sudeep.tarlekar/.ssh/id_rsa");letmut remote_callbacks = RemoteCallbacks::new();
remote_callbacks.credentials(|_url, username_from_url, _allowed_types| {Cred::ssh_key(
username_from_url.unwrap_or_default(),None,
private_key.as_ref(),None,)});letmut push_options = PushOptions::new();
push_options.remote_callbacks(remote_callbacks);letmut remote = repo
.find_remote("origin").context("remote `origin` is not configured for Git repository")?;let refspec = format!("refs/heads/{branch}:refs/remotes/{branch}");
remote.push(&[&refspec],Some(&mut push_options))?;}
Expectation
Should be able to push to non-bare local repo. If it is not allowed then what is possible workaround?
Thanks in advance 😃
The text was updated successfully, but these errors were encountered:
Description
Hello all,
I am working on some Git related service and I want to push to remote repo, which happens to be clone of local repo on filesystem. But when try to push from clone to remote(basically on local file system) I end up with following error.
Explanation
May be following sequence diagram will help to clarify what I am trying to achieve. The reason we are creating clone of repo, is because we are developing tool to work with multiple repos, so we don't want to spoil anything in main repo and we perform all required operation in clones repo and once everything is complete without error just push the changes to remote branch.
Sample code
Expectation
Should be able to push to non-bare local repo. If it is not allowed then what is possible workaround?
Thanks in advance 😃
The text was updated successfully, but these errors were encountered: