none
Adding files to GIT repositories programatically RRS feed

  • Question

  • I am working on a tool , which should add files from a local folder to GIT repository on a button click. I am using C# language. I did a lot of googling, but coldnt find any useful references. Can some one please share a reference if you have  any to achieve the same.
    Monday, July 9, 2018 12:55 PM

All replies

  • Please clarify whether you're talking about a VSTS Git repo or GitHub.

    For GitHub please post your question in their forums.


    Michael Taylor http://www.michaeltaylorp3.net

    Monday, July 9, 2018 2:38 PM
  • I think the most easy way is install command line tools for working with git and then write program to execute comands. Visual Studio works that - when you click on push button it execute push command of some tool for working with git.

    I don't understand what means add files from local to server repository. You can push added files only or do you want to push all changes into server branch?

    Monday, July 9, 2018 4:34 PM
  • Sorry for insufficient information. I am talking about VSTS GIT repositories
    Wednesday, July 11, 2018 7:28 AM
  • I have some files on my local directory on my machine. Which I need to add to GIT repository on a button click. I have built a tool using C#, in this tool I have to add I functionality to copy files from  local directory to GIT repository on a button click.
    Wednesday, July 11, 2018 7:31 AM
  • If git is installed then you can just call the Git command directly which is easiest.

    If not then you'll need to use the TFS REST API to push the files. But to do that you have to create the git repo locally (or clone an existing one), then update the files and then push and sync the repo back. A while back I blogged about doing this when migrating from TFS to VSTS. You can see the notes I made here.

    The problem I ran into with the REST API is that it is a challenge sending arbitrary changes. The issue is that you have to know whether you're adding, deleting or updating each file otherwise it won't work. If this is a brand new repo then you can simply send everything as an add but for an existing repo you have to track it yourself. That is what the .git folder is about on the file system. What you'd end up having to do (from what I could figure out at the time) is enumerate each file. If the file exists in the repo already then it is an update (or not modified). If the file does not exist then it is an add. The hard part comes with the deletes. You actually have to walk the remote repo and "delete" any files that aren't on the local system anymore. 

    For my purposes it was easier to use Git command line. For you it might be better to write the code.


    Michael Taylor http://www.michaeltaylorp3.net

    Wednesday, July 11, 2018 2:08 PM