working on a project on github, in the project itself there are 2 branches, beta and alpha, usually worked in the alpha-branch if I check in the git git branch then only 1 alpha-branch displayed. Now there is a situation that needs to be shed in beta, but in the list of branch only alpha. How can I launch it on beta-branch ?

after the comment I checked the git branch -r , and the truth is a number of remote branches are displayed .. tell me how to launch it in this case?

  • if I create a beta-branch in the project on the local repository and push it, will it be right? - YoroDiallo
  • please attach the output of the git branch -r command to the question - this is the display of branches in all remote repositories connected to your local one. You can change the question by clicking the edit below question text. - aleksandr barakin
  • @alexander barakin you are right, when you enter the git branch -r command, all remote branches are displayed. to launch it you need to do a similar operation - git push github.comsomething / project.git beta-branch? - YoroDiallo

1 answer 1

team (shown and its approximate output)

 $ git branch -r origin/Π²Π΅Ρ‚ΠΊΠ°1 origin/Π²Π΅Ρ‚ΠΊΠ°2 repo2/Π²Π΅Ρ‚ΠΊΠ°3 repo3/Π²Π΅Ρ‚ΠΊΠ°4 

will show all branches of all remote repositories connected to your local repository.

repositories appear under those (arbitrary) names under which they are connected. in this case: origin , repo2 and repo3 .

origin name β€” by default, assigned to the remote repository, for example, when running git clone .

in principle, to send changes from the current branch to any of the branches of any of the connected repositories, you can perform:

 $ git push имя-рСпозитория имя-Π²Π΅Ρ‚ΠΊΠΈ 

For the example above, you can send changes to, for example, origin/Π²Π΅Ρ‚ΠΊΠ°2 , like this:

 $ git push origin Π²Π΅Ρ‚ΠΊΠ°2 

but sending changes from an arbitrary local branch to an arbitrary remote one most likely will not work and you may receive an error of the form:

error: src refspec branch2 does not match any

This suggests that you must explicitly indicate the source . it can be the name of a local branch, a hash of a particular commit or a label (including β€œspecial” - HEAD , which indicates the current commit where your working copy of the repository is switched). like that:

 $ git push имя-рСпозитория источник:Π²Π΅Ρ‚ΠΊΠ° 

but this is not a "victory" either. most likely, you may receive an error of the form:

To url repository
! [rejected] source -> branch (non-fast-forward)
error: failed to push some refs to 'url repository'
hint: Updates were rejected because of a remote branch
hint: counterpart. Check out this branch and merge the remote changes
hint: (eg 'git pull') before pushing again.
hint: See the git push - help for the details.

this means that your current commit cannot be linked by a chain of commits to a commit pointed to by a remote branch (remember, a branch in git is just a floating pointer to a commit).

and you had to act a little differently.

for example:

  1. create a local branch based on the remote one and switch to it:

     $ git checkout -b Π²Π΅Ρ‚ΠΊΠ°2 origin/Π²Π΅Ρ‚ΠΊΠ°2 
  2. make the necessary changes, make the necessary commits.
  3. send these changes to the remote repository:

     $ git push 
  • Thank you very much for such a detailed answer) - YoroDiallo