Skip to content

Instantly share code, notes, and snippets.

@idiotandrobot
Last active May 25, 2024 08:15
Show Gist options
  • Select an option

  • Save idiotandrobot/e6bce99f6c5ed5b3f4aa5d61e31ba7e3 to your computer and use it in GitHub Desktop.

Select an option

Save idiotandrobot/e6bce99f6c5ed5b3f4aa5d61e31ba7e3 to your computer and use it in GitHub Desktop.
string directory = ""; // directory of the git repository
using (PowerShell powershell = PowerShell.Create()) {
// this changes from the user folder that PowerShell starts up with to your git repository
powershell.AddScript($"cd {directory}");
powershell.AddScript(@"git init");
powershell.AddScript(@"git add *");
powershell.AddScript(@"git commit -m 'git commit from PowerShell in C#'");
powershell.AddScript(@"git push");
Collection<PSObject> results = powershell.Invoke();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment