Pushing a new branch in GIT

I use GIT and I created a new branch (named foo ) on my local one (one that does not exist in the repository). Now I made some changes to my project source files (wizard) and made all these changes in this new branch. What I would now like to do is redirect this new branch to the remote repository. How can i do this? If I just started git push when I am on the foo branch, this will cause the whole branch to return to the repo. I do not want my changes to be set for mastering. I just want to move this new branch to the main repository.

+7
git
source share
6 answers

Yes. He will prompt you to install upstream .

Example

 git branch --set-upstream origin yourbranch 

The same goes for everyone except the branch name. Follow the onscreen instructions.

+8
source share

To insert a branch into a remote repository, you must use this syntax

 git push (remote) (branch) 

Usually the first remote (and often unique) is called the "source", so in your case you will run

 git push origin foo 

It is generally recommended that you run a slightly more complex command.

 git branch --set-upstream-to origin/foo 

because "--set-upstream-to" (abbreviated "-u") has set tracking on this thread and will allow you to simply push other changes

 git push origin 

"Tracking branches are local branches that have a direct link to the remote branch. If you are in the tracking branch and type git pull, git will automatically know which server will be pulled from and the branch to join." (cit. git)

+6
source share

to the local branch and use: git push -u origin <branch> . this will create a new branch on the remote control and push all changes.

+2
source share

git push origin foo should do the trick. In recent versions of git, only push individual branches (so that git push will work until you check foo ) unless you change the push behavior in git config.

Link can be found here.

+1
source share

If the upper thread is specified by OK, run the following command:

 git push origin foo:foo 
+1
source share

use git remote -v to show your name and the address of the remote repo:

 origin ssh://**/*.git (fetch) origin ssh://**/*.git (push) 

origin is your remote repo name on local: you can use this command to redirect a new branch to the original repository:

 git push origin [your-branch-name] 

Like this:

 git push origin foo 
+1
source share

All Articles