

Recent versions also include sparse-checkout, in case you needed more incentive to upgrade.

#Git change branch to master branch update#
If you’re on a Mac like me, you can brew upgrade git or download Git to update the version. # Git 2.27- git config -global alias.new '!git init & git symbolic-ref HEAD refs/heads/main' # Git 2.28+ git config -global faultBranch main You can set new projects created on your machine to start with main branch as well.

$ git branch -u origin/main Set Default For New Projects This is handy if you are working on local forks of OSS - Thanks to $ git branch -unset-upstream Make sure you’ve pushed your main branch, then head to - docs here 4.

Rename branches git branch -m master main # history unchanged git push origin HEAD I’m not interested in discussing reasons to do this here, it has been rehashed thousands of times already. (I recommend avoiding git pull in general: it's a convenience command that is, well, inconvenient.For my own reference, and anyone else interested in moving primary git branch from master to main. If you have control over a pre-receive or update hook on the server, you can forbid them. Note, too, that git pull makes these kinds of "reversed" merges (well, reversed from one particular point of view from another rather narcissistic viewpoint, they're entirely correct!). Note that this kind of reworking of commits assumes you have not delivered the merge commit and the subsequent commits to any other Git repository, or that if you have, everyone else who uses that other repository is OK with having master change in an unusual fashion. Or: git checkout master & git reset -hard rework Assuming you have built the new chain and are happy with it, and are still on the rework branch: git branch -f master rework This is because the first parent of any merge commit is always the commit that was HEAD at the time you ran git merge. This chain of commits, unlike the original chain, has a merge commit whose first parent is the commit you want as its first parent. Once you have built up this new graph segment on this new branch named rework, you can forcibly re-point the label master to point to the final such commit. If you do have uncommitted changes-the image above looks like gitk output, and gitk invents a fake commit-graph node for uncommitted changes-you can do all of this in a separate work-tree, or just commit the changes first, so that you have a clean tree in which to work. Since you have at least three commits that come after the merge, you will need to copy those commits as well: $ git cherry-pick. To do that in Git, check out the second parent-preferably while also attaching a new branch name to it-and run git merge ID-of-first-parent (note that you may use the two hash IDs directly, or any spelling as found in the gitrevisions documentation that finds them): $ git checkout -b rework What you can do is make a new merge, in the other order, so that the first parent of the new merge is the node that is the second parent of the current merge, and that the second parent of the new merge is the first parent of the current merge. No commit can ever be changed no power on earth can do that. Unfortunately, once a merge commit is made, it cannot be changed. That is, the mathematical properties of the graph are not dependent on path order, and most parts of Git descend both paths simultaneously, but for some purposes, especially including git log -first-parent, you may really want to control which parent is the first parent, and which is the second. But to Git, the -first-parent flag to git log will trim away all merge-commit edges that are not the first commit. In this particular mathematical formation, all edges are equal: it does not matter if you go from a merge commit whose node ID is c123456 backwards through its first parent edge to commit a000000 or through its second parent edge to commit b000000. The commit graph, like any graph, can be defined as G = (V, E) where G is the graph and V and E are the vertex (or node) set and edge set respectively. However, Git itself does give some significance to some paths through the graph. As evolutionxbox commented, you cannot always trust the coloring provided by graph- viewers (how much to trust depends on the specific viewer).
