aaragon
aaragon

Reputation: 2400

How do I push a new branch without pulling

So I've worked on new features and I realized that it would be too complicated to commit locally to master branch. Thus, I created a new branch as follows:

$ git stash branch project_0.2 stash@{0}

The problem of course is that when I try to push the new branch to the server I get:

$ git push origin master
To https://svn.tudelft.nl/git/project.git
 ! [rejected]        master -> master (non-fast-forward)
error: failed to push some refs to 'https://svn.tudelft.nl/git/project.git'
hint: Updates were rejected because a pushed branch tip is behind its remote
hint: counterpart. Check out this branch and integrate the remote changes
hint: (e.g. 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

I've been looking on the internet and everywhere I see that I should git pull and merge the changes. I tried this (before I made a backup), and I get:

$ git pull
remote: Counting objects: 1105, done.
remote: Compressing objects: 100% (304/304), done.
remote: Total 725 (delta 501), reused 552 (delta 382)
Receiving objects: 100% (725/725), 5.29 MiB | 0 bytes/s, done.
Resolving deltas: 100% (501/501), completed with 165 local objects.
From https://svn.3me.tudelft.nl/git/project
   5d6516c..fd424b5  master     -> origin/master
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> project_0.2

I'm not sure what I should do here so I stopped. Also, the changes are so deep that it will take me forever to merge. I thought there may be a smarter way to just push the branch to the server. In this way, I can get help from the other members of my team in fixing the code. Is this possible?

Upvotes: 2

Views: 6144

Answers (2)

Sergio Prats
Sergio Prats

Reputation: 1213

If you want to isolate your new features from what you have been doing in your master branch, you have to do what @UniCoder says. Create a new branch with:

git branch NewBranchName

Activate it with:

git checkout -b NewBranchName

Do your developments, Add the objects you need, commit the work you have done on this feature and then create the new branch as:

git push origin --set-upstream NewBranchName

For later pushes you only have to put "git push origin"

Upvotes: 1

UniCoder
UniCoder

Reputation: 3233

Create new branch first using

git checkout -b NewBranchName

It will create a new branch on your local machine, now push this new branch.

git push origin NewBranchName

Upvotes: 3

Related Questions