Thursday, February 20, 2020

Local repos co-development setup



Assume

  • you and your colleagues are co-developing feature that you want to share latest commits every so often without publishing to the center repo
  • or on rare case: you have work done on two clones of a same repo (on same machine or different machines)

Let's say they are:

  • ~/ws1/repo
  • ~/ws2/repo

To setup the sharing so that you can pick commit from ~/ws1/repo to ~/ws2/repo and vice versa:

1) Setting up ~/ws1/repo:
  • cd ~/ws1/repo
  • git remote add ws2 ~/ws2/repo/  // Add remote repo. This is an one time setup
  • git fetch ws2                               // Always run this to update remote repo information
  • now you can see/pick commits from remote repository:
    • git log ws2/master
    • git cherry-pick 
2) Setting up ~/ws2/repo (exact same steps)

  • cd ~/ws2/repo
  • git remote add ws1 ~/ws1/repo   // Add remote repo. This is an one time setup
  • git fetch ws1                               // Always run this to update remote repo information
  • now you can see/pick commits from remote repository:
    • git log ws1/master
    • git cherry-pick 

More possibly, over 2 repos remotely with SSH:


git remote add ws1 user@server:~/src/repo/

Extra Use cases:
* When you have multiple clones of a remote repo for some reason, and remote pull is slow, you can setup one of the local repo has a upstream and use that to pull from the remote server. But having the rest of local clone pull from this local master.

git branch --set-upstream-to ws2/my_branch

No comments: