Let\'s say that I have a desktop pc and a laptop, and sometimes I work on the desktop and sometimes I work on the laptop.
What is the easiest way to move a git repo
What is the easiest way to move a git repository back and forth [between 2 computers]?
I work on one weak computer I travel with (a laptop), but build on a more powerful computer located elsewhere. I use git all the time to sync from my laptop to the other computer using a script. I just type this command to run it:
sync_git_repo_from_pc1_to_pc2
That's it! It usually takes about 25 MB of data and ~30 sec to 1 min, even when using a cell phone wifi hotspot and working on a repo that is dozens of gigabytes in size. I'm ssh'ed into PC2, so I do git log -1
on PC2 to verify that the sync worked, then I run the build command. Works perfectly. Give it a shot. See the links below for details.
Note: the cloned repo on PC2 will be on a git branch named somename_SYNC
. Modify the script appropriately if you'd like it to have the same branch name instead of always using a "SYNC branch". It is possible to modify the script to get an effect more like Scenario 2 below if desired. Nevertheless, doing Scenario 2 manually isn't hard, so you might just want to continue to do Scenario 2 manually. It's Scenario 1 where the automated script is the most beneficial and time-saving, as it allows an easy and rapid "modify, sync, build" workflow where "modify" takes place on PC1, "sync" is run from PC1 but affects also PC2, and "build" takes place on PC2.
I want the git repositories to be identical, so that I can continue where I left of at the other computer. I would like to make sure that I have the same branches and tags on both of the computers.
Go to https://github.com and create an account and optionally (recommended) set up ssh keys.
Now use their web interface to create a new repository.
Find the new repository ssh or https clone URL. Ex: git@github.com:ElectricRCAircraftGuy/eRCaGuy_dotfiles.git or https://github.com/ElectricRCAircraftGuy/eRCaGuy_dotfiles.git.
Clone the project onto PC1. Ex:
git@github.com:ElectricRCAircraftGuy/eRCaGuy_dotfiles.git
cd eRCaGuy_dotfiles
And repeat that exact same clone command on PC2.
Now on PC1, make some changes, commit them, and push them to your "remote" repository on github:
# edit some files, then do the following
git add -A # stage ("add") all changed files to be committed
git commit # commit them
git push # push them to your remote github repo
Now on PC2, pull in your changes:
# pull all changes from github (which includes the changes
# you just pushed from PC1) to PC2
git pull
Now you can edit files on PC2, commit them, and push them to github using the commands shown just 2 steps above, and then from PC1 you can run git pull
to pull in those changes from PC2.
Keep doing this process, as required, working on PC1 OR PC2, and easily sharing the files and splitting your work between the two computers. Just remember that all your changes must be committed and pushed to github on one PC before you can check them out (pull them) and continue working on the other PC.
If you ever get into a situation where files are a bit out-of-sync between the two PCs, you'll have to maybe use some extra branches, do some merges, resolve conflicts, etc. Then, it becomes more similar to working with a small team where you are all working on the same repo. Google is your friend. Git is very very very powerful, and has a command, set of commands, or workflow for just about everything.
Couldn't you just create a remote repository on GitHub, BitBucket or GitLab? (The latter two companies offer unlimited free private repositories). When you finish the day at work, simply use git push
to push your changes to the remote repo. When you get home, just do git pull
to pull your changes from work onto your home machine. Likewise, when you finish at home, do git push
and then when you return to work, do git pull
.