Scenario
2 to 3 remote repositories in GitHub and 2 local repositories:
- [GitHub] Go to an owner repository (eg OpenMage).
- [GitHub] Fork owner's repository (from item 1).
- [GitHub or BitBucket] Our application with custom code.
- [Local] Mirror of fork in GitHub, 2 branches: upstream remote to item1, and origin remote to item 2. This local repo is for code contribution to owner.
- [Local] Application, 3 or more branches: upstream remote to item1, origin remote to item 2, and a master branch remote to item 3. Master contains our custom code specific to our application.
To update our fork (items 2 & 4), we update our local repositories by fetching and pulling from upstream, then push to remote item 2.
To update our application (items 3 and 5), in local, we fetch and pull from upstream, switch to master and merge it with upstream. Finally, we push master to remote item 3.
Prerequisites
Clone a local copy of the forked repository in GitHub. With TortoiseGit:
Update in GitBash Show archive.org snapshot
Only 3 steps to update the forked repo:
- Launch gitBash in the root folder
- Pull from upstream (owner of the repo)
- Push to origin (forked repo)
kiat@win10 MINGW64 /d/Work/Oro/platform-application (master)
$ git pull https://github.com/oroinc/platform-application.git master
remote: Enumerating objects: 36, done.
remote: Counting objects: 100% (36/36), done.
remote: Compressing objects: 100% (15/15), done.
remote: Total 45 (delta 24), reused 33 (delta 21), pack-reused 9
Unpacking objects: 100% (45/45), done.
From https://github.com/oroinc/platform-application
* branch master -> FETCH_HEAD
Updating e27cd733..046f118f
Fast-forward
composer.json | 3 +-
config/config_dev.yml | 26 +-
config/config_prod.yml | 22 +
dev.json | 1 +
dev.lock | 1380 ++++++++++++++++++++++++++++++++---------------
public/.htaccess | 3 +
var/OroRequirements.php | 10 +-
7 files changed, 992 insertions(+), 453 deletions(-)
kiat@win10 MINGW64 /d/Work/Oro/platform-application (master)
$ git push origin master
Counting objects: 45, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (45/45), done.
Writing objects: 100% (45/45), 29.02 KiB | 803.00 KiB/s, done.
Total 45 (delta 25), reused 0 (delta 0)
remote: Resolving deltas: 100% (25/25), completed with 10 local objects.
To https://github.com/kiatng/platform-application.git
e27cd733..046f118f master -> master
Alternate Method using TortoiseGit
In the local repo which was cloned earlier, create a upstream
remote pointing to the owner's repo:
Now, to update the forked repo:
- [TortoiseGit] Switch to branch
master
- [TortoiseGit] Pull from remote
upstream
branchmaster
- [TortoiseGit] Push to remote
origin
branchmaster
Update Local Repo from Upstream
Prerequisites
First create a local branch upstream_master
to hold the latest branch from upstream. Then do a hard reset:
$ git branch upstream_master
$ git checkout upstream_master
$ git fetch upstream
$ git reset --hard upstream/1.9.4.x #default branch
Now, upstream_master
has the latest updates. Before we can merge this to local master, we need to remove unwanted files. We remove the files manually and then commit changes to upstream_master
.
Update by master merging upstream_master into it
The forked repo is for contributing to the owner's repo. For production or actual running the application, we need to have a separate local and remote repos running locally or in a server. There will be time when we need to update our application with the latest version from the owner. I created a branch upstream_master
to hold the latest version from the owner. To update the local master
branch, do:
- [TortoiseGit] Switch to branch
upstream_master
- [TortoiseGit] Pull from remote
upstream
branchmaster
- [TortoiseGit] Switch to branch
master
- [TortoiseGit] Merge from branch
upstream_master
tomaster
git merge --allow-unrelated-histories upstream_master
- [TortoiseGit] If there are conflicts, resolve them by using the files from
upstream_master
, then commit the changes intomaster
- Use TortoiseGit resolver to go through the file one by one or batch by batch with shift-clicking
- If there are massive number of files to resolve, see Git – Resolve Merge Conflicts Show archive.org snapshot
- [TortoiseGit] Push to remote
origin