edgarstack
edgarstack

Reputation: 1114

Git: Automatically configure remotes when cloning

I have a repository I with two different remotes: origin and upstream. However every time I clone the repository I have to manually configure the upstream by:

git remote add upstream <url>

Is there a way to configure a git repository such that its already configured with upstream upon cloning ?

Upvotes: 2

Views: 661

Answers (2)

ElpieKay
ElpieKay

Reputation: 30966

Create an executable hook post-checkout in /foo/hooks/.

A sample:

#!/bin/bash    
git remote add upstream <url>

When you are going to clone a repository and you want the upstream to be automatically configured, add an option to specify the hook path:

git -c core.hookspath=/foo/hooks/ clone <url>

So that post-checkout under /foo/hooks/ will be invoked by the checkout in git clone as if the hook is under the newly cloned repository.

For easier use, you can make an alias, for example ch standing for clone with hooks:

git config --global alias.ch "-c core.hookspath=/foo/hooks/ clone"

Then git ch <url> works.

Upvotes: 4

Himanshu
Himanshu

Reputation: 12685

git remote -a 

It will show both the remote and upstream.

We use upstream mainly when creating a fork from the main repository and whenever we update, we update our remote repository. Letting know the owner of the repository to create a pull request from updated fork(origin).

Upvotes: -1

Related Questions