made

git branch local_branch_name origin/branch_name 

after the change I am writing

 git push origin/local_branch_name 

mistake

enter image description here

where is the mistake? How can you solve?

  • There is one team in question, and another in the screenshot. And judging by the Git Bash Prompt, you're in a detached HEAD. And that's bad. - D-side
  • @ D-side, and so it turns out this way git branch local_branch_name origin/branch_name not a good option for work? It turns out you just need to clone yourself in master and push as origin, right? - bemulima
  • git branch local_branch_name origin/branch_name is to create a branch based on another one, but go to it !!!! need to explicitly go through checkout. - KoVadim
  • @KoVadim, and how, in this case, to push , nothing? - bemulima
  • first you need to put commits in order, and then everything will turn out by itself. I would write out the hashes of commits first (the first 6-7 characters are enough), then I switched to the master (git checkout master). And then he created a normal branch and commited commits there. To paint in detail? - KoVadim

1 answer 1

Trouble

git branch does not switch the active branch!

You made a branch, but did not switch to it, and you did not commit it.

In the "daily git-usage" you will almost never use the git branch directly, rather you will use checkout with the -b option (from b ranch):

 git checkout -b новая-ветка 

... that will do the branch where you ( HEAD ) are now , and also switch to it. If you want a branch in some other place, then specify it:

 git checkout -b новая-ветка место-новой-ветки 

Do not touch the remote-branch (what are the origin/* )!

The only thing for which they are needed is to indicate to you where the server branches are located. Even when interacting with the server, you will not specify these branches, since they do not exist for the server. And commit in them is not accepted. The general view of git-push is:

 git push <сервер> <откуда-локально>:<куда-на-сервере> 

Plus abbreviated forms:

 git push <сервер> <откуда-локально> # зальётся в ветку "за которой следит" git push # как выше, но текущая ветка 

What to do?

I suppose events developed as follows:

 git checkout origin/DIMA # это уже крайне подозрительное действие git branch DIMA origin/DIMA # создали ветку, но не переключились git commit ... # что-то закоммитили: ой, вы же были в detached HEAD вне веток! git commit ... # ещё что-то закоммитили! 

... and if I’m about right, then the problem will be solved simply by the "loss-of-commits" ( English dangling commits ) to the branch where they were originally intended; if the branch is now exactly behind them (and has not gone forward since then), then fast-forward will occur. Therefore, we will add the --ff-only flag to the --ff-only so that if I am wrong (and you broke the repository more than I thought), the merge did not happen.

First, we fix the "losers", denoting a stable place in history for them.
"In any strange situation, make a branch"

 git checkout -b marker 

Now you have to go where these commits were meant.

 git checkout DIMA 

And now let's try to rewind DIMA forward, including the former "losers":

 git merge --ff-only marker 

... and if merge occurred, it seems that I guessed your script, and it looks like, with my manipulations (after the first command => after the third), something like this:

commit scheme

And now, in theory, you can do just git push (without all) and the branch will go to the server.


What kind of "losers"?

These are commits that cannot be reached from the "fixed points" by following the "back" (following the links to the parent commits). Such "fixed points" are branches (branch) and tags (tag).

All commits that Git cannot reach from such points are garbage and should be deleted sometime , they cannot be guaranteed to be safe, they can be eaten at any moment by git gc . From here and the "losses", for the history these commits are lost, if someone (for example, git reflog ) did not record their hash.

Such commits are caused by, for example, git commit --amend , or any meaningful (not fast-forward) git rebase .

  • one
    Ten commits out of ten! Excellent answer) - Nick Volynkin
  • one
    Oh, and my name is Dima. Bonus - raviga