Chris Noldus
Chris Noldus

Reputation: 2502

Pushing one git branch requires a pull on another?

I'm a bit of a git n00b, and I am having some difficulty with branches. I don't think this question has been asked, however it could just be that I'm not looking for the right keywords.

Situation: I have a remote git repository and I have checked out the master branch on machine 1. I have done the same on machine 2, except that I have created a new branch (sandbox) and checked that out.

I pull, make changes, commit and push stuff on Machine 2 - no problems.

I then make some changes on Machine one, commit, and try to push, except I get this error:

To [email protected]:/project.git
! [rejected]        sandbox -> sandbox (non-fast-forward)
error: failed to push some refs to '[email protected]:/project.git'
To prevent you from losing history, non-fast-forward updates were rejected
Merge the remote changes (e.g. 'git pull') before pushing again.  See the
'Note about fast-forwards' section of 'git push --help' for details.

If I do a git pull, I get:

Already up-to-date.

So at the moment I have to

git checkout sandbox
git pull
git checkout master
git push

And then its all fine. It seems to me, that given these are different branches, there should be no need for me to do a pull on the sandbox branch to push changes on master. I could understand it if I was trying to merge them back, but that will probably never happen.

I suspect my config file is a bit wrong, so here it is:

(Machine 1 - master) .git/config

[core]
    repositoryformatversion = 0
    filemode = true
    bare = false
    logallrefupdates = true
[gui]
    wmstate = normal
    geometry = 1920x970+0+0 368 203

[remote "origin"]
    url = [email protected]:/project.git
    fetch = +refs/heads/*:refs/remotes/origin/*

[branch "master"]
    remote = origin
    merge = refs/heads/master

And

(Machine 2 - paid) .git/config

[core]
    repositoryformatversion = 0
    filemode = true
    bare = false
    logallrefupdates = true

[remote "origin"]
    fetch = +refs/heads/*:refs/remotes/origin/*
    url = git+ssh://[email protected]/project.git

[branch "master"]
    remote = origin
    merge = refs/heads/master

[branch "sandbox"]
    remote = origin
    merge = refs/heads/sandbox

It should be noted, the the same problem happens in revers - after a push on master, I can't to a push on sandbox without checking out master, doing a pull and then switching back to sandbox.

There must be an easier way - any help would be appreciated.

Upvotes: 2

Views: 346

Answers (1)

Chris Noldus
Chris Noldus

Reputation: 2502

Found an answer:

git config --global push.default tracking

This seems to have solved by problem.

Aquired answer courtesy of This Site

Upvotes: 1

Related Questions