How to use git2 rs push to remote end with username and password?

I saw there's a issue, is it a bug?
I have tried many ways, but it doesn't work, who can give me ademo code to push with username and password.

Thank you.

The issue you posted is for pushing to a remote that uses ssh and an RSA key. This particular combination is known to be problematic on windows for libgit2 in general, not just the Rust wrapper.

Feel free to post them so that people can tell you what you're doing wrong rather than just giving you one of the possible correct ways to do it.

That said last time I used git2 I did something like this:

    let repo = git2::Repository::open(repository_path)?;

    let head = repo.head()?;
    let head_branch_name ="Invalid UTF-8")?;

    let remote_name = repo.branch_upstream_remote(head_branch_name)?;
    let mut remote = repo.find_remote(remote_name.as_str().context("Invalid UTF-8")?)?;

    let mut remote_callbacks = git2::RemoteCallbacks::new();
    remote_callbacks.credentials(|_, _, _| git2::Cred::userpass_plaintext(username, password));

    let mut push_options = git2::PushOptions::new();

    remote.push::<&str>(&[], Some(&mut push_options))?;

I made a file in github repo
It can clone / pull / commit, but function push5 doesn't submit the changes to the remote.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.