Reputation: 848
Is it possible to merge/rebase remote tracking branch in git (local)?
I know it can be modified by git pull. But can we modify the remote tracking branch by any other git commands (locally)?
Upvotes: 1
Views: 822
Reputation: 1324268
. just wondering how push will modify remote tracking branch ? (when we push our local branch to hosting site, automatically in the background, git merge runs?
There is no merge happening on the remote side:
push --force
)It is common to use a remote tracking branch to rebase a local branch on top of:
git switch my-feature-branch
git fetch
git rebase origin/main
git push --force
That way, when you do a PR (Pull Request), requesting your remote feature branch to be merged to the remote main branch, said request will be trivial to solve (since your feature branch will just add new commits on top of the remote main
).
The remote tracking branch origin/main
was modified by git fetch
(using a default refspec +refs/heads/*:refs/remotes/origin/*
)
Upvotes: 1
Reputation: 535139
can we modify the remote tracking branch by any other git commands (locally)?
Both push
and fetch
(which is what pull
is) modify remote tracking branches. You cannot do it any other way, because the entire purpose of a remote tracking branch is (wait for it) to track the remote, ie to match it perfectly. If you could do anything to upset that match, by editing a remote tracking branch directly without communicating with the remote, your repo would break.
Upvotes: 1