Git merge with cloned projects (best practice)
I’m looking for the best practice for working with GIT. Here is my problem:
I have a BASE project and, for each client, I clone it. Because those projects will be very similar (only changes some config files and images), and each web project will be stored in a different directory.
- The Git Repositories tab from eclipse it's empty
- git: Unable to Clone Private Repositories, Error: Repositories not found
- Git push new project permission denied
- Git: move existing repository from PC to server, clone from server
- Set up new project repository on windows LAN envirnment
- Git repositories on shared hosting with ssh access - multiple users / one ssh account
So I think the best practice is to clone the base project, make some changes and upload to the new clients dir.
Until here is all fine but: How do I merge changes if I found a critical bug or if I add a new feature to all (or to some) of the projects? Do I need to create a patch or something similar? How?
I would like, if you please, an easy understanding answer, because I am not a GIT master (but I want to learn!)
Thank you very much!
2 Solutions collect form web for “Git merge with cloned projects (best practice)”
You might want to weigh your options depending on the changes in your base repository (client repositories) that you want to incorporate in some/all of your client repositories(base repository).
Assume what you want the changes to be incorporated into is a client and the changes that you want are in base.
Let’s say you have a remote that points to the base repository.
So, in your client repo, you would:
git remote add basepro <url>
Here are some cases you might encounter:
You make a basic change/ major bug fix in your base repository that you want incorporated in all/some of your clients. In case your base repository is also local and rewriting commit history doesn’t affect you in anyway, you can consider a rebase:
git rebase -i basepro/master
This will take you back to the last common commit of the base project and your client project and then apply all the commits you have made to the client project one by one. But, you might have to manually merge a few changes here and there and continue:
git rebase --continue
Rebase is your friend if you want the commit history to look as if you have that feature in the base before you started working on changes specific to the client.
In your other client projects, you might similarly rebase to the branch you want to or even specific commits that you want to be rebased from.
You want only specific commits in a base repository to be applied to client repositories or specific commits of one client to be applied to another.
git cherry-pick -Xpatience <commit>
You can also specify a range of commits.
You have similar files in client1 and client2, and they are both based on a file in the base. Now, you want to merge these files in the two clients for another client 3.
In this case, you might want to use
git merge-file <client1file> <basefile> <client2file>
The merged file will be written into
client1file. In this case, you have to first
checkoutthe required files into your working tree, when you are in client 3 repo.
git checkout baserepo/master -- basefile
would checkout the basefile.
You could rely on
git mergein case your base now has some features that you want in your clients and that wouldn’t affect your independent development of client or in any other case where you want a branch to be merged in your current branch directly.
You might want to use an ours strategy to keep client repo’s changes in case of conflicts
or do a manual fix, just to be sure.
git merge -s ours baserepo/master
Applying patches can also be done as explained to me in this answer:
What you can do – is you can add other repositories as remotes and cherry pick changes into them.
git remote add project <address> git checkout project master git cherry-pick <sha1>