2

i am new to azure devops and facing problem to integrate between azure devops and github, may be you could help. my question is how can i push commits that are done on the azure devop repo to corresponding repo which resides on my github account?

For example: 1)i import a file abc.py from github private repo 2)i make changes to abc.py in azure devops repo and commits it. 3)now all the commits i made to abc.py on master branch of azure repo should be pushed to abc.py of master branch in my private github repo from where it was previously imported.

thanks for your help.

Pruthvi Raj
  • 574
  • 8
  • 15

1 Answers1

2

You can try adding a Command Line Script task to the agent job of the build pipeline, and then push the update to github via the git command.

The commands added in the task are as follows:

    git clone https://github.com/XXX/XXX.git
    git config --global user.name "XXX"
    git checkout master
    git add .
    git commit -m "abc"
    git push https://%gt%@github.com/xxx/xxx.git

Here is my sample: enter image description here

Note:You need provide your github PAT in push url, like the example below:

git push https://{yourPAT}@github.com/xxx/yyy.git

To protect your PAT, you could use secure variable , such as gitHubPat, change variable type to secret. enter image description here

Then you could add an Environment Variable, in my example: gt. Then set its value to $(gitHubPat).In command line task, you use double %% to get the value of environment variable "gt".

If you need to push the updates from your azure devops repo to github repo in real time, you can set in Build Triggers and check the Enable continuous integration option.So if your master branch changes, it will trigger ci build, your update will be pushed to github repo. enter image description here

Hope this helps.

Hugh Lin
  • 17,829
  • 2
  • 21
  • 25
  • I need to buy you a beer. struggled for two days to get it done. thanks once again for the detailed answer . this is what I was looking for. have great day. – Pruthvi Raj Jul 05 '19 at 03:53
  • 1
    Could this be used for a two-way sync? So if I also make a change in GitHub, can I get that pushed back to Azure DevOps? – Steve L. Feb 23 '20 at 20:43