The question is that I locally have a project in which there are 3 branches when I push , only master sent to the repository

For some reason, I remember that earlier when I created local branches, they too were sent to a common repository with a stream of changes being sent.

As far as I understand, I can use the command

 git push -u origin branch 

but as far as I understand, this command will create branches deleted and then it will be necessary to delete them, because if you delete them locally in the repository, they will still remain.

What to do?

  • The question is not very clear. Do you want to save branches to a remote turnip and at the same time do not want to remove them from there later, although this is required? - Yuriy SPb
  • @Yuriy SPb)) yes, I agree it turned out to be confusing, in general, it seems to me that when pushing is done, the branches should also appear in the repo and this is not the same as the git push -u command ... or not? or exactly the branches are sent to the repo? - Aleksey Timoshchenko

2 answers 2

According to en-SO , in order to push all local branches to a remote repository at once, you just need not specify a specific branch to -l or directly indicate that you need to push everything:

 git push origin 

or

 git push origin --all 

Otherwise, if you specify a k-l specific branch / tag with the push command, then only he / she will be sent

 git push origin branch1 

You can also send several specific branches at once simply by listing their names like this:

 git push origin branch1 branch2 
  • I was helped by the entry with the -all tag, but as far as I understood it, it did the same thing as I described with the -u tag. - Aleksey Timoshchenko
  • @AlekseyTimoshchenko, to be honest - I don’t know what it is doing -u , so I can’t tell you the difference and whether it is) - YuriySPb
  • The @AlekseyTimoshchenko parameter -u or --set-upstream establishes a long-term connection between local branches (of the type of feature ) and tracking branches, which correspond to the branches of the remote repository. That is, the next time when git push feature -> origin/feature automatically pushed, and with git pull , changes are picked up from origin/feature -> feature . - Nick Volynkin
  • @AlekseyTimoshchenko If the question is, what and how many branches is sent - then read about the settings push.default matching and push.default simple - for example, I once described in one of the related questions: ru.stackoverflow.com/questions/543167/ ... - AK

note about the -u option (long form - --set-upstream ) on the push command, i.e. what is the difference between the team

 $ git push origin ветка 

from the team

 $ git push -u origin ветка 

the only difference in the results of these two commands is that the second command (the one with the -u option ( --set-upstream )) will add your local storage to the config file (that is, to the .git/config file .git/config ) section describing the branch ветка :

 [branch "ветка"] remote = origin merge = refs/heads/ветка 

it is clear that such a section will be added only if it was not there before, i.e. use the option -u ( --set-upstream ) for an individual branch makes sense only once (re-executing the git push -u origin ветка command will not be any different from the git push origin ветка command).

the meaning of this section is that for a branch a ветка indicated:

  1. from which remote repository (in this case, origin ) “pull up” changes
  2. from which branch of this repository they “pull up” (in this case, from the ветка )

and what are the consequences of having such a section?

  1. a visual consequence manifests itself, for example, when executing a command

     $ git remote show origin 

    in the list of branches configured for git pull , you will see a record and a branch about the ветка (besides the already configured master branch):

     ... Local branches configured for 'git pull': ветка merges with remote ветка master merges with remote master ... 
  2. a functional consequence will manifest itself when executing the git pull command when the ветка is current.

    1. if the mentioned section is absent, then you will receive an error message of the following form:

       There is no tracking information for the current branch. Please specify which branch you want to merge with. See git-pull(1) for details git pull <remote> <branch> If you wish to set tracking information for this branch you can do so with: git branch --set-upstream-to=origin/<branch> ветка 
    2. if the section is present, then “normal” pull will be executed.