I need to push a local folder to a Git repository. Following is what I have tried till now:
public static async Task CommitAllChanges(string message,string filePath, string cloneUrl)
{
try
{
var _folder = new DirectoryInfo(filePath);
string path = LibGit2Sharp.Repository.Init(_folder.FullName);
using (var repo = new LibGit2Sharp.Repository(path))
{
var files = _folder.GetFiles("*", SearchOption.AllDirectories).Select(f => f.FullName);
Commands.Stage(repo, "*");
repo.Commit(message, new LibGit2Sharp.Signature("sormita", "sormita@gmail.com", DateTimeOffset.Now),
new LibGit2Sharp.Signature("sormita", "sormita@gmail.com", DateTimeOffset.Now));
//push files
string name = "origin";
repo.Network.Remotes.Add(name, cloneUrl);
var remote = repo.Network.Remotes.FirstOrDefault(r => r.Name == name);
var options = new PushOptions
{
CredentialsProvider = (_url, _user, _cred) =>
new UsernamePasswordCredentials { Username = "email", Password = "password" }
};
string pushRefSpec = @"refs/heads/master";
repo.Network.Push(remote, pushRefSpec, options);
}
}
catch (Exception ex)
{
throw ex;
}
}
I am able to push but no files are shown in the repository in GitHub.
The above code will successfully push a directory to Github repository.
How can I use GitHub PAT token for this Push?
Set that as your password to the credentials provider. A PAT is a password.
And if you've used your actual password in your question, please change it immediately.