Merging local git repository to remote

I have a pretty simple remote git repository:

*---*---(a)---*---(b, HEAD) (master)

      

Also I was working in a local repo of a project whose initial state corresponds to the state after commit (a) and has many branches:

(a')---*-------------*-----------* (my-master)
        \___________/___________/__ (my-dev)
         \______________..._______/ (feature, hotfix branches)

      

However, the original commit of the local repo was not obtained properly (i.e. with git commands), but by copying the project files (hence the name (a '), since it matches the same state as (a) but different from a git point of view). Now I want to merge my local changes to the remote repo, but also "bind" somehow the original commit of the local repo to commit (a) to get the following image:

*---*---(a)---*-----------------------(b)-- (merge-commit, HEAD) (master)
          \________________________________/ (my-master)
                  \___________/___________/__ (my-dev)
                   \______________..._______/ (feature, hotfix branches)

      

What's the best way to do this?

+3


source to share


1 answer


Thanks to poke's comment , I found a solution that suits my purposes.

# add remote repo and fetch it
git remote add repo <repo_addr>
git fetch repo

# create new branch for rebasing onto
# here 'a' is hash of the commit (a)
git checkout a
git branch my-huge-feature

# rebasing my-master branch onto my-huge-feature
git checkout my-master
git rebase my-huge-feature

# fast-forwarding my-huge-feature pointer
git checkout my-huge-feature
git merge my-master

      



After these steps I am getting my local commit history integrated into the remote repo history (pushing my huge function omitted).

However, the command rebase

does not keep the branch history, so the remote repo will keep my commits on the same branch. While this is fine for me, I would really appreciate it if this answer comes with a method to keep the branching history.

+2


source







All Articles