2

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?

aaragon
  • 2,314
  • 4
  • 26
  • 60
  • You created your branch in a most bizarre way. In any case, the typical workflow is to just push the new branch and then create a pull request going back into `master`. Too many problems to risk giving an answer. – Tim Biegeleisen Jul 06 '17 at 11:32
  • @TimBiegeleisen it seemed a good solution after reading [this answer](https://stackoverflow.com/a/30927991/611873). – aaragon Jul 06 '17 at 11:34
  • If you can tell us what you want to do with this branch, maybe an answer or suggestion can be given. – Tim Biegeleisen Jul 06 '17 at 11:36
  • I would like to set it later as the main branch because it has deep changes to the structure of the code. The problem is that people have been working with the main branch and have committed changes to it (also I don't want to loose this work). – aaragon Jul 06 '17 at 11:37
  • The log tells everything. I always wonder why so many users are using `git pull` or `git push` without any options while the configuration is obviously not supportive yet. – ElpieKay Jul 06 '17 at 11:37
  • @ElpieKay I just did pull properly, but just wondering whether there's a better solution to what I need. – aaragon Jul 06 '17 at 11:38
  • Just create a branch the normal way, push it, and then merge later with master when you are ready. You are overcomplicating things. – Tim Biegeleisen Jul 06 '17 at 11:39
  • I couldn't do that because I had uncommitted code in the main branch. That's the reason I used stash. – aaragon Jul 06 '17 at 11:41
  • @aaragon The key point is that you need to understand what git refs( including branches, stashes, tags, etc.) are and how they work with commits and each other. Once you know them well, all paths naturally show up in your mind. – ElpieKay Jul 06 '17 at 13:32

2 Answers2

3

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
UniCoder
  • 3,005
  • 27
  • 26
1

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"

Sergio Prats
  • 1,043
  • 1
  • 14
  • 19