Reputation: 11
I am trying to clone a remote repo to my local workspace, and push the content to a new bare repo I set up to maintain, this repo need to have occasional updates from upstream repo, and new contents need to be pushed to local repo as well.
Here is a example:
git clone ssh://[email protected]/project
and I created a bare repo as project_local
mkdir project_local.git
git init --bare --share=2 project_local.git
once the remote repo is cloned in my workspace, since this remote repo has multiple branches,
branch1
branch2
.
.
branchN
Here is what I have done to get all the branches from remote and push to my local bare repo.
cd project
git branch -a >&/tmp/branchinfo
sed s,.*/,, /tmp/branchinfo >&/tmp/branchinfo1 #this remove everything before the last '/' before the actual name of the branch
for i in `cat /tmp/branchinfo1`; do git checkout $i; done #checkout all the branches from remote site.
for i in `cat /tmp/branchinfo1`; do git push project_local.git $i; done # Push all the remote branches to local repo I created with all contents.
after this, the contents from remote repo are now in my local bare repo, but how can I fetch and merge all remote changes of individual branches to the corresponding branches in the local repo I created?
I have tried using 'git remote add' but that only does the fetch the refs, it doesn't actually do the merge content.
Thank you in advance for any help I can get.
Thanks
Upvotes: 1
Views: 215
Reputation: 129564
sounds like all you are doing is updating branches. There is no merge unless you are counting a fast-forward merge which is really just a reference update.
All you need to do is
git fetch original-repo
git branch -r | cut -f3- -d'/' | xargs -i{} git push new-repo original-repo/{}:{}
This assumes you already added a remote entry for your new repo and called it new-repo
.
Upvotes: 1