# How can i push locally created branch on a repository to origin via Ansible

**URL:** <https://forum.ansible.com/t/how-can-i-push-locally-created-branch-on-a-repository-to-origin-via-ansible/22720>\
**Category:** Ansible Project\
**Created:** [October 4, 2016, 3:21pm UTC](https://forum.ansible.com/t/how-can-i-push-locally-created-branch-on-a-repository-to-origin-via-ansible/22720 "2016-10-04T15:21:37Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ishan\_jain](https://avatars.discourse-cdn.com/v4/letter/i/dc4da7/32.png) [@ishan\_jain](https://forum.ansible.com/u/ishan_jain)\
**Post date:** [October 4, 2016, 3:21pm UTC](https://forum.ansible.com/t/how-can-i-push-locally-created-branch-on-a-repository-to-origin-via-ansible/22720/1 "2016-10-04T15:21:37Z")

</div>

Seems like there is isn’t any module in Ansible which can commit back to a GIT repo. My case is such that i am allowing the user to create a new branch in any of our several repositories and with the help of templates, generate some necessary files, all this via ansible. I am able to clone the repo (even a branch/tag) via GIT module, create a new branch with shell module, populate it with templates, but now i need to push the new branch and its contents and this is where i am stuck. GIT push would prompt for username and password which is something i have in the variables but don’t know how to use in Ansible shell command. Any ideas how to proceed here ?

---

<div class="post-metadata">

**Author:** ![Alexander\_H\_Laughlin](https://avatars.discourse-cdn.com/v4/letter/a/ce7236/32.png) [@Alexander\_H\_Laughlin](https://forum.ansible.com/u/Alexander_H_Laughlin)\
**Post date:** [October 4, 2016, 8:51pm UTC](https://forum.ansible.com/t/how-can-i-push-locally-created-branch-on-a-repository-to-origin-via-ansible/22720/2 "2016-10-04T20:51:34Z")

</div>

I think something like the below would work to solve your problem with the variable interpolation.

`

- name: Push git commits with local variables.

hosts: localhost

vars:

username: git\_username

password: git\_password

tasks:

- name: Set origin to include username and password.

shell: “git remote set-url origin https://{{ git\_username }}:{{ git\_password }}@yourhost.com/storage/repo.git”

- name: Push to origin.

shell: “git push origin branch”

`

That is, if you can safely transmit the passwords via https. If you’re using http this would be incredibly unsafe.

You could also look at setting the credential.helper variable in git (`git config --global credential.helper store`), but that’s beyond the scope of this mailing list.

---

<div class="post-metadata">

**Author:** ![ishan\_jain](https://avatars.discourse-cdn.com/v4/letter/i/dc4da7/32.png) [@ishan\_jain](https://forum.ansible.com/u/ishan_jain)\
**Post date:** [October 5, 2016, 8:29am UTC](https://forum.ansible.com/t/how-can-i-push-locally-created-branch-on-a-repository-to-origin-via-ansible/22720/3 "2016-10-05T08:29:17Z")

</div>

I found a single GIT command to do that.

git push origin \<tag/branch\> --repo [https://username:pass@repourl.com](https://username:pass@repourl.com)
