6

I am working on the develop branch on my computer. I have done a lot of changes that I do not want to push, but I want to keep them. What I did is to change the translator behavior on my project and I would like to test it a little longer before pushing it and deploy it to production. But I would like to continue to work on develop or any other branches and be able to apply theses changes.

There is the ideas I came up with:

  1. Keep all of those files (do not git-add them) and commit only files I actually want to commit. But this solution make my "git status" very messy (lot of modified files) and I believe it will generate errors and lead to the commit of wrong file(s).

  2. Git stash save "Translation" and apply it when I want to use it. But I will have the same issue with a messy git status where I will have to choose which one of my files I want to commit or not.

  3. Create a new branch with my new feature on it, but as soon as I will merge it to my working branch I will commit the merge as the same time

Do you know any other workflow to keep a list of changes to a lot of files and apply/remove theses changes ?

iBadGamer
  • 566
  • 6
  • 22

6 Answers6

0

Something like git-flow or gitlab-flow suits very well.

From what I've read, I can conclude that your project consists of 2 modules, and you modify both of them.

One module is stable, but you've modified it anyway and want to test your modifications more thoroughly, and another one is a work in progress.

I would use your 3rd variant, but merge your working branch into your new feature branch.

Or, if you want to separate your modifications to a "stable" module, you could keep them in a separate branch.

That is, you get 3 branches:

  • your work on "unstable" module, "stable" module without your latest changes;
  • your modifications of "stable" module;
  • merge of two above

Branching in git is cheap and easy, you can create any amount of branches.

wl2776
  • 4,099
  • 4
  • 35
  • 77
0

You could have your main local branch rebase onto an intermediate branch that is the one tracking the distant branch. You then report your commit from yor main local branch to the tracking one via cherry-pick, and then rebase your main local onto the updated tracking branch.

Laurent G
  • 397
  • 8
  • 16
0

Keep the local unfinished work on a separate branch and push it.

  1. It will allow you to craft commits properly and not do a huge monster commit at the end.
  2. It will allow you to have a copy of your code on the server so that in case of a disk crash or something similar, you won't lose your work.
  3. It will allow others to see your code and review it before you deploy to production.

The deployment will happen usually off a single branch. As long as you don't merge your changes into that branch (though you need to verify this at your place), you're safe.

Noufal Ibrahim
  • 71,383
  • 13
  • 135
  • 169
0

I would suggest another idea.

  1. Create different commits

  2. Push only specific commits to master

  3. Push another commits whenever you need to so that your git status won't be messy.(There won't be much tracked files in git because files are already committed)

The procedure is already explained here:

How can I push a specific commit to a remote, and not previous commits?

how do you push only some of your local git commits?

NID
  • 3,238
  • 1
  • 17
  • 28
0

Take the 3rd option, create a new branch for your feature.

You don't have to merge it into develop until you're ready - merge develop into feature instead, whenever there's a change you want to test.

  • To work on clean development code: check out develop.
  • To work on the new translator code: check out feature and merge in the latest changes from develop.
  • When the feature is complete: merge develop into feature one last time (if it's not already up to date), then check out develop and merge feature into it.
brehonia
  • 66
  • 2
0

One solution I have used is to have a second remote repository, with the branches and commits that I didn't want in the first repository.

You have to take care to make sure that you're pushing to the proper repository, but it does sound like it would meet the needs of your situation.

user151841
  • 17,377
  • 29
  • 109
  • 171