Git Local To Remote Repository Connection
Git Local to Remote Repository Connection (Without Losing Local Files)
Scenario
Local directory: aerostitch-nest/
Remote repository: git@rdbb.bitbucket.org:darmist/aerostitch-nest.git
Step 1: Go into Local Project
cd aerostitch-nest
Step 2: Initialize Git (If Not Already)
git init
Step 3: Add Remote Repository
git remote add origin git@rdbb.bitbucket.org:darmist/aerostitch-nest.git
Verify Remote
git remote -v
Step 4: Fetch Remote References
git fetch origin
Step 5: Choose One Case
✅ Case A: Remote Repository Is Empty
git add .
git commit -m "Initial commit from local files"
git push -u origin master # or main
⚠️ Case B: Remote Repository Already Has Commits
Create a Local Branch
git checkout -b local-branch
git add .
git commit -m "My local files"
Merge Remote History
git checkout master # or main
git pull origin master --allow-unrelated-histories
Resolve conflicts if any
Push to Remote
git push -u origin master
✅ Result
Local directory is now fully connected to the Bitbucket repository and all files are tracked.