One of the Git strategies that have worked well in my current project that I am working on is to have a separate fetch and push URL for a given repository.
What this allows you is to have a strategy where all developers pull the latest code from the main repository, however, before they contribute back to it, they need to do so by first pushing against a fork of the main repository. Once the developer is happy with his series of commits and is ready to merge back to the main repository, they create a pull request with the modified unit of work.
This process has been really helpful in ensuring that all code gets reviewed before it is merged in to the main repository.
So here is how you can set up a separate Git push URL through a command line:
Setting a separate Git push URL
Step 1: List your existing remotes in order to understand your current local setup.
$ git remote -v # origin email@example.com:PROJECT/REPOSITORY.git (fetch) # origin firstname.lastname@example.org:PROJECT/REPOSITORY.git (push)
Step 2: Use
git remote set-url --push to modify the push URL only of your current repository. Using
git remote set-url
will modify both fetch and pull URL’s.
$ git remote set-url --push origin email@example.com:USERNAME/REPOSITORY
Step 3: Verify that the remote URL has been changed successfully.
$ git remote -v # origin firstname.lastname@example.org:PROJECT/REPOSITORY.git (fetch) # origin email@example.com:USERNAME/REPOSITORY (push)