Forum Discussion

drhorg2230's avatar
drhorg2230
Copper Contributor
Jun 09, 2024

Sync 2 Git repos

 I cloned a month ago a Github public repo directly into a new private Azure DevOps repo, by using https://learn.microsoft.com/en-us/azure/devops/repos/git/import-git-repository?view=azure-devops , because we are implementing new software which is hosted in a Github public repo. The reason for saving the code also in ADO is since we have few parameter files that we need to modify. After this original clone directly from GitHub to ADO, I cloned locally on my laptop and created a new branch for DEV based on main, by adding one commit that contain 4 yaml files : 2 new parameter files and 2 updated files. Then pushed DEV branch to ADO.
 
git clone https://ContosoOrg/Project/_git/RepoName 
git switch main
git checkout -b DEV
#add 2 new yaml files and update 2 files
Git add .
Git commit -m “Added and Updated Config files”
Git remote add github https://github.com/Software/Project.git
git push -u origin DEV
In the meantime in Github there were 4 additional commits on the main. I need to update both the main and DEV branches in ADO based on Github main branch changes, now and in future for any further Github new commits. I am fairly new to Git but reviewed the documentation in depth. My question is can you please check following steps and let me know if make sense to you, or you see an issue.
 
git fetch github 
git switch main 
git rebase github/main
git push -u origin main
git switch DEV
git rebase github/main
git push -u origin DEV
 
 
 
 

1 Reply

  • Consider the following as well:

     

    1. Force Push May Be Required

    If you've already pushed main or DEV to Azure DevOps before rebasing, a regular git push may fail. In that case, use:

    git push --force-with-lease origin main
    git push --force-with-lease origin DEV

    This is safer than --force because it ensures you don’t overwrite someone else’s work.

    1. Avoid Rebasing Shared Branches

    If other developers are working on the same branches, rebasing and force-pushing can cause conflicts for them. In that case, consider using git merge instead of rebase.

    1. Automate the Sync

    If you want to keep GitHub and Azure DevOps in sync continuously, consider:

    • GitHub Actions to push changes to Azure DevOps on every commit.
    • Azure Pipelines to pull from GitHub and push to Azure DevOps.

Resources