How to conveniently sync a file between two git repositories
The only other alternative would be a post-commit hook on repoA
, which would, on each commit:
- check if the file is part of said commit
- copy it in repoB with the right path.
Does syncing the .git repo between computers cause an issue?
I've kept my code checkouts in Dropbox now for 5 years writing code most every day. I use this to sync these changes between my desktop and laptop. This includes doing large refactorings that change dozens of files at a time.
Very rarely I have encountered problems, though they have a couple of times been severe (a corrupted repository) so you need to push early and often. Those rare problems are well worth the incredible convenience of being to continue work from right where you left off when switching between machines.
I've also tried this with Transporter with much, much less success. The Transporter file watcher doesn't seem as good, which led to conflicts every few weeks. Additionally, the syncing is much slower—whereas Dropbox seems to get things matched within a few seconds if both machines are up on the same network, Transporter had a median time of 30 seconds, but sometimes up to a few minutes.
How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?
Copy the diff file to the root of your repository, and then do:
git apply yourcoworkers.diff
More information about the apply
command is available on its man page.
By the way: A better way to exchange whole commits by file is the combination of the commands git format-patch
on the sender and then git am
on the receiver, because it also transfers the authorship info and the commit message.
If the patch application fails and if the commits the diff was generated from are actually in your repo, you can use the -3
option of apply
that tries to merge in the changes.
It also works with Unix pipe as follows:
git diff d892531 815a3b5 | git apply
Related Topics
Indenting Multi-Line Output in a Shell Script
How to Schedule Tcpdump to Run for a Specific Period of Time
Check If Environment Variable Is Already Set
New to Linux Kernel/Driver Development
How to Diff a Directory for Only Files of a Specific Type
How to Use Linux Command Sort to Sort the Text File According to 4Th Column, Numeric Order
Shared Libraries: Windows VS Linux Method
Why Does Perf Stat Show "Stalled-Cycles-Backend" as <Not Supported>
Linux, Why Can't I Write Even Though I Have Group Permissions
What Are My Environment Variables
Rm Fails to Delete Files by Wildcard from a Script, But Works from a Shell Prompt
Difference Between Netstat and Ss in Linux
Run a Shell Script in New Terminal from Current Terminal
How to Find Out What Inotify Watches Have Been Registered
In Linux Determine If a .A Library/Archive 32-Bit or 64-Bit
Delete .Ds_Store Files in Current Folder and All Subfolders from Command Line on MAC
Tool to Visualize the Device Tree File (Dtb) Used by the Linux Kernel