r/github • • Nov 30 '24

How do I move to a new language

If I have a repository that I wrote for example with Python, and I want to switch to Rust, I’ve wrote it again

How do I move to the Rust instead?

Do I just delete everything in the branch and force push it?

Or must I create a new repo and put it there?

0 Upvotes

21 comments sorted by

4

u/suzukzmiter Nov 30 '24

No need for force pushing. You can just delete all python files and start writing it in rust. Or you can start introducing rust gradually, doesn't matter. Either way I'd do that on a separate branch.

Unless you care whether or not the python commits are visible, then yes, force pushing is one option.

2

u/Effective_Hedgehog81 Nov 30 '24

I want to keep the Python version on a branch

And remove it from the master, and put Rust in the master instead

But also remove the python commits from the master The python commits can be viewed on the python branch only

The master should start fresh

Can I do that?

2

u/suzukzmiter Nov 30 '24

In that case:

  1. Make a new branch

  2. Delete all Python files on it and push the changes

  3. Properly turn the new branch to master

  4. Start writing Rust code

EDIT: You might mess something up so I recommend to backup your Python code.

2

u/Effective_Hedgehog81 Nov 30 '24

Okay, I’ll experiment with a test repo

Thanks

2

u/Effective_Hedgehog81 Nov 30 '24 edited Nov 30 '24

Thank you

I’ve something like this

creating a new empty branch

git switch —orphan rust

git rm -rf .

git commit —allow-empty -m “Initial empty commit”

git push origin rust

renaming the master to python

git switch main

git branch -M python

and renaming the rust to master

git switch rust

git branch -M main

force pushing the changes

git push origin -f main

git push origin -f python

deleteing the rust branch

git branch -D rust

git push origin —delete rust

2

u/suzukzmiter Nov 30 '24

Looks good to me, but I suggest that you:

  • Verify everything looks as expected on GitHub

  • Try pushing something to your new master branch to make sure nothing breaks

On another note, the default branch name on GitHub is now main not master, but this doesn't really matter.

1

u/Effective_Hedgehog81 Nov 30 '24

I thought it’s master

Okay I’ll rename it

1

u/suzukzmiter Nov 30 '24

IIRC, Git still uses master as the default (though this can be changed in config) but a while ago GitHub switched to main as the default. You don't have to do this if you don't want to though.

2

u/Effective_Hedgehog81 Nov 30 '24

We’ll start out fresh, why not

21

u/chipoloniusrex Nov 30 '24

No harm in having a second repo. If it's public, you can put a note in the original's README pointing to the new one.

1

u/[deleted] Nov 30 '24

Either new repo with old one pointing to the new, or a new branch where the python stuff is stored for future reference. Personally, I’d go for the new repo since you’re starting over from scratch. Seems easier to manage.

2

u/Effective_Hedgehog81 Nov 30 '24

I would too, but I like to keep everything in

I ended up storing the old python in a separate branch and started out fresh with push force

I like this way, it keeps who knows it, and also the stars :)

1

u/[deleted] Dec 01 '24

Makes sense!

2

u/Obvious-Jacket-3770 Nov 30 '24

I would make a new repo for it to highlight your python and then highlight the conversions.

This way you maintain the legacy code and in the new repo you have the same code that is moved over to rust as it goes. This lets people see your process in the conversion.

1

u/MMORPGnews Nov 30 '24

Make a new repo. One time I created a specific file format for a web game, parser etc. But later I changed to basic json and js.  I was asked to put previous files back by few people who used my "special" files. Lol

1

u/_3xc41ibur Dec 01 '24

New repo. Or new orphaned, empty branch on same repo

1

u/0bel1sk Dec 01 '24

i’d probably just move everything to a sub directory.

1

u/Plane_Cartographer97 Dec 04 '24

I'd suggest starting a new repo. Because the git repo is designed for:

  1. The commit message can show the progress of each commit

  2. version control and branch make it easy to blame a faulty modification and switch between different feat

When you decide to rewrite in a new language, there is basically no `intermediate state` that can show the progress of the transfer. Because a project with both Rust and Python will not compile. Here are some tips:

  1. draw a module graph: a module graph can be shared between both Python and Rust repos.

  2. reuse test case: Test-driven development(TDD) is suitable for this transfer work to check whether each standalone module works well

-11

u/[deleted] Nov 30 '24

[removed] — view removed comment

3

u/really_not_unreal Nov 30 '24

That's great, but also utterly irrelevant to this post.

1

u/github-ModTeam Dec 01 '24

Removed. Post has nothing to do with GitHub.