Skip to content

Instantly share code, notes, and snippets.

@auricgoldfinger
Last active July 2, 2021 00:03
Show Gist options
  • Save auricgoldfinger/0afb65323b7f5144a0b9e33093fe77f7 to your computer and use it in GitHub Desktop.
Save auricgoldfinger/0afb65323b7f5144a0b9e33093fe77f7 to your computer and use it in GitHub Desktop.
My git svn workflow using rebase

Inspiration:

http://flavio.castelli.name/2007/09/04/howto_use_git_with_svn/
http://stackoverflow.com/questions/16329776/how-to-keep-a-git-branch-in-sync-with-master
http://stackoverflow.com/questions/2695119/is-git-svn-rebase-required-before-git-svn-dcommit
http://stackoverflow.com/questions/2389361/undo-a-git-merge-that-hasnt-been-pushed-yet

# checkout svn trunk revision 123456
git svn clone -r123456:HEAD https://svn.example.com/svn/trunk/project

# create branch on which you do your modifications
git checkout -b feature-branch

# do your modifications, then commit locally, eventually "git add" new files
git commit

# sync with svn
git checkout master
git svn rebase
git push origin master # -f after git svn dcommit followed by git svn rebase. Origin is personal, NO upstream
git checkout feature-branch
git rebase master # in IntelliJ, select git-branches popup > master > "Rebase onto". Easier merging of conflicts!
git push origin feature-branch -f # allowed since this is my personal one

# feature branch is now up to date with svn. Merge it into master
git checkout master
git merge feature-branch # No rebasing here! This is going upstream.

# only when multiple svn rebases have taken place, squash the duplicate commits
git log --oneline --decorate
git rebase -i HEAD~2 # 2 is the number of commits without the merges
git svn dcommit
git pull
git push origin master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment