I recently completed a full migration of our D365 F&O source code from one Azure DevOps organization to another. Since I couldn't find a comprehensive guide online, I'm sharing the complete process that worked for me.
Prerequisites
- Git installed
- git-tfs installed (`choco install gittfs`)
- Git Bash
- Visual Studio 2022
Phase 1: Clone Source Repository
git tfs clone "https://dev.azure.com/SOURCE-ORG" "$/PROJECT/Trunk/Main" --changeset=XXXX
Use `--changeset=XXXX` to specify the first changeset you want to include in the migration.
Phase 2: Clean Metadata (CRITICAL STEP!)
Each commit contains a `git-tfs-id:` line pointing to the source server. **This MUST be removed** before pushing to the destination.
**Open Git Bash**:
cd /c/path/to/cloned/repo
FILTER_BRANCH_SQUELCH_WARNING=1 git filter-branch -f --msg-filter 'sed "/git-tfs-id:/d"' -- --all
**Verify the cleanup:**
git log -1
The commit message should **no longer** contain `git-tfs-id:`.
**Remove empty commits (if any):**
git rebase -i --root
In the editor, change `pick` to `drop` for any empty commits. If the first commit is empty, delete the entire line.
## Phase 3: Prepare Destination
1. Go to destination Azure DevOps → **Repos** → **TFVC**
2. Create the folder structure (e.g., `$/PROJECT/trunk/Main`)
3. Add a `README.txt` file
4. Check-in the changes
**Clone the destination repository:**
git tfs clone "https://dev.azure.com/DEST-ORG" "$/PROJECT/trunk/Main" NewRepo
Phase 4: Migration with History
cd NewRepo
# Add source repo as remote
git remote add oldrepo "C:\path\to\source\repo"
git fetch oldrepo
# Rebase commits onto destination
git rebase --onto tfs/default --root oldrepo/master
# Push to TFS (each commit becomes a separate changeset)
git tfs rcheckin