r/developers • • Sep 11 '25

Opinions & Discussions Senior Dev Tip**

This is something I started doing around year ten of my programmer career. I encourage everyone to do the same.

write a script to clone a fresh copy of your codebase instantly on your system. Great for reviews and health checks. If you are using git, this should be some git commands and a few cp's

bonus points: add a parameter to the script that checks out a specific branch.

branch=$1 git checkout $branch

iddqd: extend the script so that it instantly builds and launches the code after checkout. React Native devs should be able to do this fairly easy with the cli tools available

I use this technique to speedup reviews and to avoid interrupting my own work.

it's okay to have multiple copies of the same codes guys 😀

6 Upvotes

40 comments sorted by

•

u/AutoModerator Sep 11 '25

JOIN R/DEVELOPERS DISCORD!

Howdy u/joy-of-coding! Thanks for submitting to r/developers.

Make sure to follow the subreddit Code of Conduct while participating in this thread.

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

4

u/letelete0000 Sep 11 '25

I work at a company that introduced a similar concept to their code editor. It allows you to switch between different branches without committing files. This way, you can always go back to the exact same state of the directory you had worked on before :) I find it useful.

1

u/fearthelettuce Sep 13 '25

That would be amazing

1

u/TedW Sep 13 '25

Sounds like git stash?

1

u/letelete0000 Sep 13 '25

Not sure how git stash -u (which you’re probably referring to) works under the hood now, but there used to be a known issue/or intended behavior related to the deletion of .gitignored files. The difference between stashing and using a separate workspace is that with the workspace approach, all directory contents are restored exactly to the snapshot where you left off. Not saying it’s impossible to reproduce with Git, but the workspace approach is just intuitive to work with in my opinion :)

1

u/TedW Sep 13 '25

Ah, it would get tricky with modifying ignored files. That's a rare edge case for me.

1

u/scarabeeChaude Sep 11 '25

You guys build code in order to review it?

1

u/joy-of-coding Sep 11 '25

yes. with my full chest. I build code, and I run it

1

u/eboob1179 Sep 11 '25

You dont need a script for that you can just use a bash alias.

1

u/joy-of-coding Sep 11 '25

Please explain this a little more. Alias is usually a one line shortcut to some other script.

What does your alias look like?

2

u/eboob1179 Sep 11 '25

Something like

alias clonebase='function_clonebase(){git clone --recursive --branch mybranch https://myrepo/myproject.git "$1"}; _clonebase'

Then you just call it like ./clonebase mydir

1

u/joy-of-coding Sep 11 '25

it's beautiful 🤩

2

u/eboob1179 Sep 11 '25

You can chain commands too in bash with &&. So like I have alias for our crazy build custom in house build manager that kills the local cached repo, cleans the project and builds like

alias deepcleanbuild=cd /opt/dev/ && rm -rf repository && cd myproj && bldr clean && bldr build

1

u/cgoldberg Sep 11 '25

bash functions exist too

1

u/eboob1179 Sep 11 '25

I know, see my first comment.

2

u/Gainside Sep 11 '25

haha yeah, game-changer. i even hacked together a little script that auto-runs tests + lints on the fresh clone

2

u/zemaj-com Sep 11 '25

I second this. Having a fresh clone script or using git worktree makes code reviews painless because you never have to stash or reset your main workspace. I also like to wire in a build or test command so that as soon as the branch is checked out it compiles and runs tests. That way you catch issues early while your primary environment stays clean.

2

u/zemaj-com Sep 12 '25

I have found that using Git worktrees is a great way to manage multiple copies of a repository. It lets you check out different branches in separate folders without copying the entire project. For example run `git worktree add ../feature feature` to create a new worktree for a branch. This approach saves disk space and makes context switching between tasks easier.

1

u/10F1 Sep 14 '25

Git work trees are such an underrated feature.

1

u/zemaj-com Sep 15 '25

Absolutely — worktrees are a game changer when you need to hop between features or bug fixes without cloning the whole repo again. I love how you can add, list and prune them with just a couple of commands, and the isolation keeps your working directories clean. I'm always surprised more teams don't take advantage of them. Glad to hear you're a fellow fan!

2

u/WiseKouichi Sep 13 '25

good idea imma try it out

1

u/Agathon813 Tech Lead Sep 12 '25

Use Git Worktrees. You're reinventing the wheel.

1

u/iammirv Sep 14 '25

I can do that in like 3 seconds with git already...

3

u/[deleted] Sep 11 '25

[removed] — view removed comment

0

u/joy-of-coding Sep 11 '25

because you lose context by doing all those things.

there are things that may not stash (like an env, and new files)

whereas creating a new folder is going to keep your IDE where it was at.

there is a chance commits on your branch may interfere with the review branch

4

u/[deleted] Sep 11 '25 edited Sep 11 '25

[removed] — view removed comment

0

u/joy-of-coding Sep 11 '25

You understand then. It’s very messy. And this is my strategy for agility. Imagine multiple vscode windows, a pot of coffee, and 5 asynchronous tasks.

If you like that, I actually make different folders for every ticket I work on. Not just reviews 😁

Think of them all as individual case studies stashed on my laptop for future reference.

Everything is fresh like QFC produce 🥬

4

u/[deleted] Sep 11 '25 edited Sep 11 '25

[removed] — view removed comment

2

u/Rough_Music7942 Sep 12 '25

And using -b <branch_name> creates a branch and checks it out in that new directory (worktree)

Great for having agents work in parallel on different features without the concern of agents stepping on each other.

Cleanup/removing the work tree is just as easy, all should be in that link.

1

u/[deleted] Sep 11 '25

[removed] — view removed comment

1

u/joy-of-coding Sep 11 '25

I use the vscode gUI for a lot of git commands myself.

But, there are projects that require multiple steps to reach buildable. By repeatedly dog-fooding those steps the code setup becomes a warn down piece of carpet that gives new comers a clear path to success.

1

u/[deleted] Sep 11 '25

[removed] — view removed comment

1

u/joy-of-coding Sep 11 '25

No, I use code-server for collaboration. I will check it out when I get a chance. Thanks

2

u/[deleted] Sep 11 '25

[removed] — view removed comment

1

u/joy-of-coding Sep 11 '25

how much money?

I am building a collab server. Thinking something like a $50 sub

https://rootnode.app

1

u/[unknown] May 19 '26

[removed] — view removed comment

1

u/AutoModerator May 19 '26

Hello u/Gold-Possible2902, your comment was removed because your account is too new.

We require accounts to be at least 15 days old to comment. This helps us prevent spam.

If you have an urgent question, message the moderators.

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.