push your branch as it is (without the current work) to remote
commit all changes to current branch with a commith you're gonna reset after
do whatever job you need to on the other branch
switch back to previous branch
reset to HEAD~1
continue your work
This is my preferred way as, with stash, you can inadvertently pop back changes that would mess up all the things and with your second scenario you need to do a lot of extra ("useless") work.
Problem-solver and fintech developer with a passion for writing. I build innovative financial solutions and share insights to help others excel in tech. Let's connect and collaborate!
Location
Lahore, Pakistan
Education
Bachelor's in Computer Science
Pronouns
he/him
Work
Software Developer at Infaque business solutions x Prodago
You're absolutely right, there are many different methods people use to achieve the same result in Git. Thank you for sharing your preferred approach! It’s always great to learn about different techniques and perspectives. Appreciate your input!
Disk is cheap. Every time you start a branch to do some work, make a worktree. Switching contexts is now as simple as 'cd'. No work lost. You just need discipline to do that EVERY TIME you need to make a branch. I have written a framework around that workflow if you're interested: github.com/matthewpersico/personal > But be forewarned - it's involved.
Soy un desarrollador que le gusta todo lo relacionado a la Programacion y busco ampliar mis conocimientos, soy dedicado, proactivo y comprometido con el trabajo
I always commit my code with the message "WIP" only or "WIP: what I am doing". I always work on some feature branch, so I don't have to create a temporary branch.
I have never in my life used git stash command :)
We're a place where coders share, stay up-to-date and grow their careers.
There's at least another solution:
This is my preferred way as, with stash, you can inadvertently pop back changes that would mess up all the things and with your second scenario you need to do a lot of extra ("useless") work.
You're absolutely right, there are many different methods people use to achieve the same result in Git. Thank you for sharing your preferred approach! It’s always great to learn about different techniques and perspectives. Appreciate your input!
Disk is cheap. Every time you start a branch to do some work, make a worktree. Switching contexts is now as simple as 'cd'. No work lost. You just need discipline to do that EVERY TIME you need to make a branch. I have written a framework around that workflow if you're interested: github.com/matthewpersico/personal > But be forewarned - it's involved.
Use git worktree, it's really useful when you need to switch to a different branch while working
Ex:
git worktree ../<dir_name> <branch name>Good info!
However it’s good practice to use things like
git switchorgit branchrather thangit checkoutfor everything now.Underrated comment
Or just clone the repo again in another folder.
Btw I think that git worktree is THE solution to this, but I also use the git stash approach
Check out GitButler.
Outstanding,
Very informative good job :)
It's me, or this post reeks of AI?
increíble... buen dato gracias por tomar parte de tu tiempo y compartir esta valiosa información.
I always commit my code with the message "WIP" only or "WIP: what I am doing". I always work on some feature branch, so I don't have to create a temporary branch.
I have never in my life used
git stashcommand :)