Create a branch from another branch without tracking it.

Usually I create a branch like this:

git checkout branch
git checkout -b new_branch

It works well because it does not automatically set the branch upstream, so it shows me a warning to click to configure upstream. I usually copy it, and then correctly track the remote branch ...

That said it was rather cumbersome ...

So I started using a new method to reduce the number of steps:

git checkout -b new_branch from_branch

Unfortunately, this gives me this result:

git checkout -b xxx origin/staging
Branch xxx set up to track remote branch staging from origin.
...

So when I try to click, it gives me this error:

fatal: The upstream branch of your current branch does not match

Obviously, the upstream is not the one I wanted ... I would prefer it to automatically add the start / xxx or not upstream at all.

, " --no-track "; ? , .

+5
4

tl; dr: , , git config --global push.default=upstream, , git push, .


Git . git push ... , ++ " ", , , , . , git push.default "", , git push, , , - , , , .

, factory -default , -, , .

git push docs, git config docs push.default:

, <refspec> ... --all, --mirror, --tags, <refspec>, remote.*.push, , push.default, , (. git-config push.default).

, , , , simple push.default: , , , .

push.default

git push , refspec. ; , (.. ), , , , . :

  • - (), refspec. , , .

  • current - , . , .

  • - , ( @{ }). , , (.. ).

  • - , , , .

    , , , . .

    git 2.0.

  • - . , , , (, maint master , , , , , maint master ).

    , , , , git push, . , , . , .

    , git 2.0 ( - ).

+1

, git checkout --track/--no-track, git branch, zorblatt , origin/master, origin/master () :

git checkout -b zorblatt --no-track origin/master

, . (, git-gui, gui.matchTrackingBranch.)

( : , , : " X Y/Z", "" "" ". " , , , .)

+4

--no-track . - , , checkout branch.

, . git, , , :

git config --global alias.nb '!bash -c "git checkout -b $1 --no-track ${2-origin/master}" -'

2 bash . - () , origin/master .

HEAD , ${2-origin/master} $2 .

:

git nb <branch-name> [<source-commit>]
0

,

. ?
, . git .
Git 1.X , git v2.X.

upstream git, . 1.X git , -.

.git/config, . git remote -v .

git release notes 2.0

https://git.kernel.org/cgit/git/git.git/tree/Documentation/RelNotes/2.0.0.txt

git push [$there] , , matching ( , ).

Git 2.0 uses semantics by default , simple


What can you do instead?

As you have discovered, the parameter --no-trackwill create a branch without upstream.

Another option:

You can create an orphan branch (a branch without a story), and then use the cherry pick to add the whole story you want to it.

git checkout --orphan <new_branch> [<sha-1>]

Now you clear the story, and you can add any commit you want.

-1
source

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


All Articles