2

I have a git repository on a server somewhere where I keep long term changes to my software. I develop this software on an Windows machine using Visual Studio. I make commits via Visual Studio and push changes to the server via a Git CLI tool. This software is mainly used on an offline machine, though some development and bug fixes are done on this offline machine.

The problem I currently have is two fold. First, it takes quite some time to copy the entire Visual Studio project folder (which also is the .git repo) from the online development machine to the offline machine, especially in view of small changes to the codebase (Sometimes I simply copy over files directly). Second, I frequently forget to move changes/"production bug fixes" (yea) from the offline machine back to the development machine.

After starting to post a question about how I might do this via git (Updating local repository from another local repository ) I found a few duplicate questions, namely this question. It provides a descent selected answer, but I am more interested in this answer. It proposes creating a --bare git repository.

My question is, in the situation outlined above, is this the correct way to implement and use a --bare repository to solve my issues?

  • On the development machine, create a clone of either the remote master repository from the server or the local repository, but with the --bare argument (git clone --bare /my_remote_path/project.git).
  • Add this repository as a/the origin to the working git directory already in place (git remote add origin /my_local_path/project.git).
  • During regular development push changes to this local, bare, repository and to the remote repository with git push origin master (to the server) and git push origin(to the local --bare).
  • To move changes from the development machine to the offline machine, copy the entire bare repository folder to the offline machine. On the offline machine add the bare repository as a/the origin (git remote add origin /my_local_offline_path/project.git)
  • Push and pull changes on the offline machine from this new origin, git pull origin/git push origin. Though this obviously won't effect untracked files, which is fine.
  • Finally, to move changes from the offline machine to the development machine, copy the entire bare repository folder to the development machine. On the development machine pull changes from the local working repository using git pull origin. To save changes to the server push from local working directory to the server git push origin master.

This workflow seems correct to me, though the only thing I think is completely incorrect is the push/pull commands to and from the bare repository; especially with regards to the local working directory on the development machine (How to denote push/pull from the server or the bare repository).

KDecker
  • 6,928
  • 8
  • 40
  • 81

1 Answers1

3

I will suggest you to bundle commits between the development machine and the offline machine.

For the reason why not suggest to use bare repo:

You can not push changes from offline machine to the bare repo on the development machine directly. Instead, you always need to copy the bare repo between the two machines. And the your repo size increase, it may slow down to copy and paste.

So you can bundle the branch/commits first, and then copy and paste the bundle file (with small size) between the two machines. Detail steps as below:

1. Bundle the commits of the master branch from development machine

In your local repo (assunme it's in C:\develop\repo), use below command to bundle the commits on master branch:

git bundle create branch.bundle master

Then the file branch.bundle will be create in your local repo.

2. Unbundle the commits of the master branch to your offline machine

Copy the bundle file branch.bundle from development machine to offline machine to a directory (such as C:\offline\branch.bundle). Then unbundle master branch in a git repo by:

git clone branch.bundle -b master repo

So a local git repo with master branch (with same commit history as development machine) is created in C:\offline\repo. And you can work with this repo and make changes.

3. Commit changes on offline machine and bundle the commits/branch

When you want to apply the changes from offline machine to development machine, you can bundle the commit firstly by:

git bundle create commits.bundle master ^commit

The commit specified in above command will tell git to bundle commits from the next commit to master branch.

And if you do not want to check the commit sha-1 value each time, you can bundl the whole master branch by:

git bundle create branch.bundle master

4. Unbundle the commits from offline machine to development machine

Copy the bundle file commits.bundle or branch.bundle from offline machine to development machine local repo directory C:\develop\repo. And apply the commits offline machine to the local repo as below:

git checkout master #If the current branch is not master branch
git pull branch.bundle master #Or git pull commits.bundle master

More details, you can refer the document Bundling.

Marina Liu
  • 36,876
  • 5
  • 61
  • 74
  • This is working mighty nicely. Especially once I finally got it all automated with a few scripts. Thanks! – KDecker Apr 30 '18 at 19:22