Restore a deleted component / error / topic (private) branch

This rule is to not intercept commits that have been ported to the remote repository. As long as I understand the general reasons for this, it is not clear to me whether this also applies to such a scenario:

Suppose I'm working on some features that take several days to develop. So, I create a MyFeature branch, check it out and pass some things. Since the work takes several days, I do not want to store it on my local machine, so for backups I push this branch to the remote one.

After finishing work, I want to somehow combine it with the master.

My questions:

  • Assuming no one else ever checks and pulls the MyFeature branch and will not base its work on committing from this branch (why would anyone want to pull out any random branch?), Is it okay to reinstall such a remote branch? (using the -force switch)
  • If for some reason this is still impractical (I would like to know this reason, though), what is the alternative? Simple merge? But if so, then later I would still like to remove the MyFeature branch from local and remote repositories. So how will this differ from (1)? I am still changing the story, completely deleting it.
  • Is the above scenario rare or atypical? I mean, when looking for an answer to this question, reading the tutorials and SO questions about git-rebase always emphasizes this danger of reloading remote branches, but never considered other use cases. IMHO, quite often work on some function longer that day, and I think that no careful developer should save changes only on his computer ...
+6
source share
4 answers

Under the assumption that no one will ever check and pull out the MyFeature branch and base their work on committing from this branch, is it normal to reinstall such a remote branch? (using the -force switch)

Not only OK rebase and force push the master branch to the remote function branch, this is the only way to get ahead of master by introducing changes while maintaining linearity. At that moment when you rebase your local function branch on another branch (for example, master ), you need to force click on the remote computer, since you really rewrote the history. There is no risk of doing any harm, as you will be the only one who works in this industry. I understand that nothing of Git is inherently evil, and every Git function has its own time and place. This is one example of a forced click.

In fact, the remote personal branch of functions is the only instance where OK to use rebase on a branch that has already been pressed on the remote. As already mentioned, you will not create problems for anyone else, as soon as you have checked this branch.

If we say that rebase public branch that many users share is dangerous, because it is likely to cause conflicts for everyone when they take the next step (except, of course, for the user who did the rebase).

+4
source

Very subjective. "This is normal?" To whom? You? To your employer? Ask them.

Regarding technical feasibility:

  • Yes, not a problem.
  • You can merge and delete a branch. I prefer this method (see "Subjective"), and I even use git merge --no-ff , so even if the merge is fast forward, a merge commit is created. Deleting a branch does not change the story; you just remove the branch pointer, not the commit.

    Another alternative is git merge --squash , which suppresses a branch to merge into a single commit, which applies to the branch you want to merge into. I'm not a fan of this, but some like it.

  • No, this is not rare or atypical.
+2
source

In my opinion, there is no problem reinstalling the function branch with only one developer. I work in exactly the same way as when I rebuild my own function branches. The git story becomes much easier to view if all feature branches are reinstalled before merging. But this is a personal preference, of course.

It splits branches that cause problems during reboot. See Explanation of why here: https://superuser.com/a/667200

+2
source

Under the assumption that no one else will ever check and pull out the MyFeature branch and will not base its work on committing from this branch (why would someone want to pull out some random branch?), Is it normal to reset such a remote branch ?

Of course, and you do not need --force for the rebase step.
You only need this in order to make your branch push.

  git checkout MyFeature git fetch git rebase origin/master git push --force 

As long as you update your branch on an upstream repo this should not be a problem.

+1
source

Source: https://habr.com/ru/post/985241/


All Articles