How to push changes back to source repo in git


I curious how one can push changes back to the git source repo.

Basically, the build changes a few source files which then need to be push backed to the source repo in git.


TeamCity does not provide a feature like that.
You can use agent-side checkout and then use command line VCS tools to perform the VCS operations within the build just like you would do in a command prompt on a local machine.
Depending on the changes, it might be good to revert the working copy to the state corresponding to the build start as TeamCity assumes no VCS changes are made during the build.


Thanks for the reply. Apologies for getting back so late.

I thought TC's auto merge feature was implemented for this scenario.

Is that true?


TeamCity automatic merge feature allows to merge a branch into another branch after successful build. This does not include ability for a build to change files before the merge occurrs.
However, if you rework your process to push the modified files into a branch, TeamCity can then be confiured to build and merge the changes on success.


Very good. Thank you for the answer. It helps quite a bit. God bless.


One more question, I am getting the following error when use a git push script during a commandline build step.

Any thoughts on this one?

Starting: E:\TeamCity\Temp\agentTmp\custom_script34180244.cmd
in directory: E:\TeamCity\Work\
\Git\bin\git.exe was unexpected at this time.
Process exited with code 255
Step Update Source (Command Line) failed

Seems like an error in the script you specified. One of the most common issues is not wrapping paths with space with quotes.

If you need more guidance on this, please include your current script.


Hi. I just saw this, it's exactly what I need to do, I've tried many different ways but I always get errors when trying to push back.

Is this included in the latest teamcity or if not can you help with a workaround?

Thank you.


Hi Ricardo,


There were several issue in this thread, please describe the one you have in detail.


Basically I want to use git to push back to origin within a build step. Been having authentication issues or can't find the repo, etc



So as I mentioned in my first reply you should use agent-side checkout and then call git commands from within a build step (just like you would do from a command line). TeamCity does not seem to blame here and you just need to figure out due git command.

Depending on the VS root settings used it might be not possible to reuse repository authentication, so you probably should supply authentication anew to the git command.


I'm using HTTPS auth and I kept getting these types of errors:

[11:18:49][Step 1/1] bash: /dev/tty: No such device or address
[11:18:49][Step 1/1] error: failed to execute prompt script (exit code 1)


When using git directly on the agent in the command line it works, same exact commands, so it's definitely TeamCity related.


Ricardo, I still believe this is more related to the environment/generic OS logic and not exactly TeamCity-introduced behavior.

Please check the related topic from our documentation to try to resolve your "script works differently" case.


I'm already using a regular user and everything I execute with that user works - just not under the TeamCity build. So I have tried a few things to try to make it work - nothing except executing the same exact thing while logged into the machine, worked.

I'll have a look at the other suggestions and let you know.


Yegor, could you please elaborate on this comment
"Depending on the VS root settings used it might be not possible to reuse repository authentication, so you probably should supply authentication anew to the git command."

What VCS root setting will enable / disable reusing the repo auth?

I always get "fatal: could not read Password for '': No such device or address'

when I try to do git push from teamcity commandline runner





Hi Scott,

I guess what you experience is related not to TeamCity per se, but to the headless execution of the process and Git client specifics.

On the Git authentication: "Default private key" is not much related to TeamCity as it depends on the ssh key saved as default for the OS user. Username/password should also be possible to feed to the git client, e.g. via git-credential ( ).


Please sign in to leave a comment.