How to use a USB stick as a remote

I have local copies of the GitHub repository on my laptop and desktop. Desktop is ahead of laptop and remote GitHub origin

. I want to push the changes to the Notebook but don't want to push the public origin

. How to set up a USB stick / external hard drive as a remote control?

+3


source to share


1 answer


Plug your USB drive into your desktop computer and assume it shows up as J:

  • Initialize a bare repo that will act like a remote:

    git init --bare J:\repo_name
    
          

  • cd

    to your local repo and:

    git remote add usb J:\repo_name
    git checkout master
    git push usb master
    
          

The fork is master

synchronized with the remote usb

. Now plug in your USB stick to your laptop and assume it shows up asD:

git remote add usb D:\repo_name
git checkout master
git pull usb master

      



If you are trying to pull a branch that doesn't exist on the laptop but it works on the desktop, you can simply do git checkout the_branch

and it will automatically pull it from usb

(if the_branch

it doesn't also exist in origin

, in which case you should do git checkout -b the_branch usb\the_branch

)

You may need git fetch

it if it doesn't find the remote usb branch.

If you later plug in your USB drive and display it as a different letter, for example K:

, follow these steps:

git remote set-url usb K:\repo_name

      

+5


source







All Articles