I don't know if this is the right way to accomplish what I need and maybe has also been asked a lot, although I couldn't find a solution.
I have mirrored a repository into my Gitlab account via
git clone --mirror https://github.com/some/repo
git remote rename origin upstream
git remote add origin [email protected]:user/my-repo.git
git push origin --all
Now I want to frequently get the changes from the upstream repository without using git pull
or git merge
, because I want the commits to be identical to the upstream branch and not "Merging upstream into origin..." commits. From what I understand, you need to
cd my-repo
git remote add https://github.com/some/repo
git checkout branch_name
git pull --rebase upstream branch_name <-- pulls the changes without merging them
git rebase <-- rebases to the fetched changes so my own changes will stay on top
This works if I do it manually for the branch, but if I want to iterate through all branches with. Please correct me if I am approaching this the wrong way!
for branch in $(git for-each-ref --format='%(refname)' refs/remotes/origin); do branch=${branch##*/}; echo "\nUpdating $branch..."; git checkout $branch; git pull --rebase upstream $branch; git rebase; done
it doesn't work and the local branches stay untouched.
I know that Gitlab provides its own mirroring tool, but it is not activated in our company.
This seems to me to be a misunderstanding of what a branch is and what it's for. You should not have any local branches corresponding to the upstream. Just
git fetch
and stop; you are now mirrored and up to date.