Reputation: 4696
I forked a repository on my Github account that has over 1000 commits and 20 branches.
I then cloned it on my local machine.
Is there any way I can update both my local machine's repo and my Github's repo with the original one with all the branches and commits?
Upvotes: 3
Views: 113
Reputation: 115
maybe it's too late, but a late answer better than nothing:
# add the upstream:
git remote add upstream https://github.com/whoever/whatever.git
#create a script to loop through the whole branches and merge changes or create them if not found
sync_all_branch () {
git fetch upstream
for upstream_branch in $( git branch -a |awk 'BEGIN {FS="/"} $2=="upstream" {print $3}' ) ;
do
if git checkout $upstream_branch
then
echo merge $upstream_branch
git merge -s recursive -Xours upstream/$upstream_branch
else
echo create $upstream_branch
git checkout -b $upstream_branch upstream/$upstream_branch
fi
done
git checkout master
}
# then call the script
sync_all_branch
#push changes to your remote repository
git push --all
if you want to rebase your branches on top of the upstream branches (delete the changes you made and not merged to the upstream), you should change
git merge -s recursive -Xours upstream/$upstream_branch
with
git rebase -s recursive -Xours upstream/$upstream_branch
and add "-f" to he last command
*the sync_all_branch script is from https://stackoverflow.com/a/7766487/2481592
Upvotes: 4