บันทึกการย้ายบ้านจาก Bitbucket ไป GitHub
เนื่องจาก Github ให้ private repository ไม่จำกัดมาซักพักใหญ่ๆแล้ว ช่วงนี้พอมีเวลาได้นั่งไล่ย้าย project เก่าๆ จาก Bitbucket มา ก็เลยบันทึกขั้นตอนไว้ซะหน่อยกันลืม
- ขั้นแรก สร้าง repository เปล่าๆ รอไว้บน github.com ก่อน เปล่าๆจริงๆ ห้ามสร้างพวกไฟล์ readme ด้วยนะ
2. Clone repository ต้นทางลงมาพักพบเครื่องเราก่อน
git clone --mirror <Bitbucket_repo_address>
3. ลองตรวจสอบดูว่าตอนนี้ origin
ชี้ไปที่ไหน ด้วยคำสั่ง
cd <repo_name>.git
git remote -v
4. ตรวจสอบว่าได้ทำการ clone branch และ tag มาครบหมดแล้ว
git tag
git branch
5. เปลี่ยน origin
ให้ชี้ไปปลายทางใหม่ที่ Github แทน
git remote rm origin
git remote add origin <GitHub_repo_address>
6. สำหรับ repository ที่เก่าจัดๆแบบของผมที่ default branch ยังเป็น master
อยู่ จะมีขั้นตอนการเปลี่ยนชื่อ default branch เป็น main
เพิ่มขึ้นมานิดนึง
git branch -M main
6. push code และ tags ทั้งหมดกลับขึ้นไป
git push --all origin
git push --tags
7. เปิดดูว่า code, tags และ history ทั้งหมดเข้าไป repository ใหม่แล้ว เป็นอันเรียบร้อย
ที่มา
- How to migrate from Bitbucket to GitHub
- Let’s move repository from Bitbucket to GitHub with all branches and commits!
- Update remote repo
- Git Upstream and Downstream
- Managing remote repositories
- How to Add a New Remote to your Git Repo
- Can a project have multiple origins?
- git-push, git-branch, git-clone Manual Page