简体   繁体   中英

pull from master while pushing to another branch

I am trying to set up a workflow that with auto-merge to master.

For that, I am working locally on a branch called dev-oshai , and want to push always to that branch on the server with: git push

When I want to pull changes I want to always pull them from master (CI will auto-merge changes to master from all developers).

For that I am using the command git pull --rebase origin master

More context and details here: https://medium.com/@OhadShai/git-mono-branch-workflow-pre-tested-commits-4b34949310ad

Is it possible to configure git that the default pull branch will be origin master so that git pull will work without always specifying the branch?

[remote "origin"]
        url = <repo_url>
        fetch = +refs/heads/*:refs/remotes/origin/*
[remote "foo"]
        url = <repo_url>
        push = refs/heads/master:refs/heads/dev-oshai
[branch "master"]
        remote = origin
        pushRemote = foo
        merge = refs/heads/master
        rebase = true

This way, when in branch master , git pull is equivalent to git pull origin -r master:master and git push is equivalent to git push foo master:dev-oshai . The urls of origin and foo are the same.

Besides true , branch.master.rebase can be assigned preserve or interactive .

When preserve, also pass --preserve-merges along to git rebase so that locally committed merge commits will not be flattened by running git pull.

When the value is interactive, the rebase is run in interactive mode.

I don't think it is possible to change the behaviour for git pull completely. (except creating an alias)
But you can make it a bit less to type.

First, set up pull to always rebase in your gitconfig.

[pull]
    rebase = true

Next, you can do a little hack. Add your remote as a new local remote, so you have it twice.
For example master.

git remote add master https://example.com/repo.git

Fetch all branches

git fetch master

And set the upstream of dev-oshai to master of the new remote.

git branch --set-upstream-to=master/master

Now you can pull from master with

git pull master

If this really is a good idea or more confusing than helpful is your decision.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM