1

I have my git repo cloned on my development server which myself and another developer would like to use. The issue is that because we are on a shared server, every time I change branch names, this also reflects for him and vice versa.

I am sure there is a way around this but I have no idea - I did think of having 2 sub folders within the main theme(master) which we clone as DEV1 theme and DEV2 theme as well as also creating the same branch names on git which we push and pull from each others theme folders? I don't know if this approach would work?

raja
  • 25
  • 5

2 Answers2

1

You can have:

That way, you each operate in your own folder/branch, while pushing to the same remote repository, and seeing the work from your colleague in the other folder.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • thanks buddy - not sure that is meant by `` - can you point me in the right direction please? – raja Mar 17 '22 at 19:19
  • @raja `` in https://git-scm.com/docs/git-worktree is the path where you want to checkout another branch from the original repository. See https://git-scm.com/docs/git-worktree#_examples. – VonC Mar 17 '22 at 19:43
  • so say I have a repo called `tmm` how can i add a worktree to that bearing in mind we are 2 developers and on the same server so do not want to checkout each others branches – raja Mar 18 '22 at 09:19
  • @raja If you are both working on the same machine, clone the repo there, then: `cd /apth/to/local/cloned/repo` and `git worktree add -b branchDev2 ../dev2 main`: that will create a `../dev2` folder, with a new `branchDev2` branch, in which the second developer can operate (add, commit, push) without being directly impacted by your changes in the main branch. – VonC Mar 18 '22 at 09:37
  • so I would never have to access his `dev2` folder or his `branchdev2` branch and be able to pull from the `main` branch to get the latest changes? – raja Mar 18 '22 at 09:48
  • @raja You can pull his changes from your folder, as long as he has pushed his changes from his folder. – VonC Mar 18 '22 at 11:15
  • so we have a branch called `development` and `master` - so long as we push to these branches, we can pull each other's changes without checking out each other's branches> – raja Mar 18 '22 at 15:04
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/243072/discussion-between-vonc-and-raja). – VonC Mar 18 '22 at 18:10
0

Use your development server as a central repository that every developer pushes to and pulls from, but have a different (probably local) repository for your actual work. That way other developers only see the things you push, not every single branch you experiment with.

Take a look at this tutorial for more details.

SebDieBln
  • 3,303
  • 1
  • 7
  • 21
  • the thing is we are using the development server which acts as out "localhost" but in fact although we have separate user accounts, essentially we are sharing the one machine which is why we are in this problem – raja Mar 13 '22 at 21:44
  • Can you setup a cloned repository in every user account and then use the above mechanism of push and pull for the central repository on the same server? – SebDieBln Mar 14 '22 at 09:13