Search code examples
gitgitlabgit-push

How to commit and push changes of tracking and un tracking files to correct branch in gitlab


We have a master branch in gitlab. And we have release v1 branch under that master branch. Under releasev1 branch I have created my Register branch. I have did checkout through source tree too. But, Some how I switched to master branch unknowingly and my changes are in master branch locally.

While push/commit the code I realise this, My current branch is master. So, I stop the commit/push changes to master.

There are lot of files newly add and also existing file changes too happen.

Is there any possible without discard these changes, push to my Register branch?

I don't want to push these changes to master which is a big problem for us. I just want to push my changes to my Register branch.

Any suggestions?


Solution

  • git stash is an ideal option for you.

    Just run git stash in your local repo, it will save your changes in a detached storage and discard them. Then switch to the appropriate Register branch and run git stash pop. If there are any conflicts, it will not remove the stash from the detached storage.

    If you are using Sourcetree then use this tutorial: https://confluence.atlassian.com/sourcetreekb/stash-a-file-with-sourcetree-785332122.html