How to copy modified files in local git repository to remote host

Stanley Meng
1 min readMar 29, 2021

This one is just kind of my cheatsheet.

The host on which runs the Build/CI process (i.e. make, gcc, unitest..etc) is in the company’s network, and my development host is at my home network.

I personally don’t like work on coding remotely on the build host, through SSH or the SSH remote addion of Vscode, and another important reason is that the DevOps team would clean up the disk on the build host once a while in order to save the disk space, without informing all the users. Therefore, I code locally in my laptop, then, run this command in the local repository directory to copy the modified files to the remote build host.

Assume my PWD is /home/smeng/dev,

  1. In my laptop, cd to /home/smeng/dev; git-checkout the work branch
  2. In the remote host, cd to /home/smeng/dev, git-checkout the work branch
  3. modify the code in my laptop
  4. Run this command:
git ls-files -m | while read line ; do scp $line remote-dev-host:/home/smeng/dev/$line ; done

--

--