开发者

My local git tracking branch isn't working properly. I need advice on how to set it up

开发者 https://www.devze.com 2023-01-31 04:16 出处:网络
So I\'m working with another developer and want to pull and push to a remote branch (that is not the remote master by the way) but I want to set up so that when I check out my local branch on my machi

So I'm working with another developer and want to pull and push to a remote branch (that is not the remote master by the way) but I want to set up so that when I check out my local branch on my machine it'll pull from and push to the remote branch without having to specify it explicitly.

I ran this command on my machine (suppose that the remote branch is called development and that the local branch I create is called dev1):

git branch --track dev1 origin/development

Then checked out my local branch dev1, changed a file, staged it, commited it and then tried to push like so:

git push origin

But then I got this message:

Everything up-to-date

Also开发者_运维知识库 I noticed extra lines in my .git/config file shortly after I created dev1 and checked it out:

[branch "dev1"]
    remote = origin
    merge = refs/heads/development

So the question is what am I missing? Basically, I wish to set this up so that I every time I have checked out dev1 and run:

git pull origin

it automatically pulls from origin/development without having to specify this explicitly and when I run:

git push origin

it automatically pushes to origin/development without having to specify this explicitly.

Also, why did it tell me 'Everything up-to-date' when there were clearly changes to push.


As mentioned in "Git push won't do anything (Everything up-to-date)", git push only pushes local branches which have been configured to push to a particular remote branch.

You dev1 branch know what to pull, not where to push, because of the push.default setting:

matching - push all matching branches. All branches having the same name in both ends are considered to be matching. This is the default.

Since your local branch hasn't the same name than your upstream branch, here is your problem.

Set push.default to tracking and it will work.

tracking - push the current branch to its upstream branch.

git remote show origin will then list the branches configured to be pushed to origin, and dev1 should be listed then.

0

精彩评论

暂无评论...
验证码 换一张
取 消