# Please consider adding a -f switch to git-clone (or something similar)

7 messages from 2015-03-07 to 2015-03-08. Participants: Diego Viola, Andreas Schwab, brian m. carlson, Kyle J. McKay.
Thread: https://gitlist.dev/t/38743

## Diego Viola, 2015-03-07 21:54

Subject: Please consider adding a -f switch to git-clone (or something similar)
Message-ID: <CA+ToGPEZN7TBcYF3o5YgbayjZ8WKok-fjTPeq5nbt2vAG1wDDQ@mail.gmail.com>
URL: https://gitlist.dev/e/CA%2BToGPEZN7TBcYF3o5YgbayjZ8WKok-fjTPeq5nbt2vAG1wDDQ%40mail.gmail.com

```
Hello,

I was thinking about creating a new repository in my home dir so that I could
keep my dot files in it.

However, I found that I can't do a `git clone url:user/repo.git .` in a
non-empty directory.

Is there a possibility of implementing a -f switch to git-clone so that when I
use that, git would still clone the repo in the non-empty directory and keep the
untracked files untracked/unstaged? (just as if I copied files to the git repo).

I know I could git-init in a empty directory and then copy the .git dir to the
non-empty directory as a workaround, but I like the idea of cloning better.

My C skills aren't that great or I would have sent a patch already.

Thanks,

Diego

```

## Andreas Schwab, 2015-03-07 22:26

Subject: Re: Please consider adding a -f switch to git-clone (or something similar)
Message-ID: <87d24kzbor.fsf@igel.home>
URL: https://gitlist.dev/e/87d24kzbor.fsf%40igel.home
In-Reply-To: <CA+ToGPEZN7TBcYF3o5YgbayjZ8WKok-fjTPeq5nbt2vAG1wDDQ@mail.gmail.com>

```
Diego Viola <diego.viola@gmail.com> writes:

> I know I could git-init in a empty directory

You can also git init a non-empty directory.

Andreas.

-- 
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."

```

## brian m. carlson, 2015-03-07 22:53

Subject: Re: Please consider adding a -f switch to git-clone (or something similar)
Message-ID: <20150307225314.GC742348@vauxhall.crustytoothpaste.net>
URL: https://gitlist.dev/e/20150307225314.GC742348%40vauxhall.crustytoothpaste.net
In-Reply-To: <87d24kzbor.fsf@igel.home>

```
On Sat, Mar 07, 2015 at 11:26:28PM +0100, Andreas Schwab wrote:
>Diego Viola <diego.viola@gmail.com> writes:
>
>> I know I could git-init in a empty directory
>
>You can also git init a non-empty directory.

I have a script to set up a new throwaway VM with my dotfiles using git.
It looks a bit like the following ($BRANCH != master):

  SSH="ssh $DEST"
  
  $SSH "cd; $GIT init"
  git push --receive-pack=$GIT-receive-pack $DEST:~/.git $BRANCH
  $SSH "
      $GIT pull . $BRANCH
      $GIT submodule update --init
  "

It relies on the ability to git init a non-empty directory.  $BRANCH can 
be master if you use the new updateInstead functionality in git 2.3.0, 
and you can use git pull from a remote location instead of the push/pull 
pair if that suits you better.
-- 
brian m. carlson / brian with sandals: Houston, Texas, US
+1 832 623 2791 | http://www.crustytoothpaste.net/~bmc | My opinion only
OpenPGP: RSA v4 4096b: 88AC E9B2 9196 305B A994 7552 F1BA 225C 0223 B187

```

## Diego Viola, 2015-03-08 00:02

Subject: Re: Please consider adding a -f switch to git-clone (or something similar)
Message-ID: <CA+ToGPHOM9mu_ng4wVc7QUGyvf09y=nDjE32oSh9JzKbpbzN2Q@mail.gmail.com>
URL: https://gitlist.dev/e/CA%2BToGPHOM9mu_ng4wVc7QUGyvf09y%3DnDjE32oSh9JzKbpbzN2Q%40mail.gmail.com
In-Reply-To: <87d24kzbor.fsf@igel.home>

```
Sorry, I wanted to say: I know I can git-clone in a empty directory
and then move the files over to $HOME.

I know I can git init in a non-empty directory. :-)

Thanks,

Diego

On Sat, Mar 7, 2015 at 7:26 PM, Andreas Schwab <schwab@linux-m68k.org> wrote:
> Diego Viola <diego.viola@gmail.com> writes:
>
>> I know I could git-init in a empty directory
>
> You can also git init a non-empty directory.
>
> Andreas.
>
> --
> Andreas Schwab, schwab@linux-m68k.org
> GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
> "And now for something completely different."

```

## Diego Viola, 2015-03-08 01:53

Subject: Re: Please consider adding a -f switch to git-clone (or something similar)
Message-ID: <CA+ToGPFSbOjfd5gJg+r-7WkwMB=m=4sOupaZo1WUn+O0bxAAXw@mail.gmail.com>
URL: https://gitlist.dev/e/CA%2BToGPFSbOjfd5gJg%2Br-7WkwMB%3Dm%3D4sOupaZo1WUn%2BO0bxAAXw%40mail.gmail.com
In-Reply-To: <CA+ToGPHOM9mu_ng4wVc7QUGyvf09y=nDjE32oSh9JzKbpbzN2Q@mail.gmail.com>

```
Something like this is the scenario I'm talking about:

$ mkdir non-empty-dir
$ cd non-empty-dir
$ touch foo bar baz
$ git clone -f url:user/dotfiles.git .
$ git status
On branch master
Your branch is up-to-date with 'origin/master'.
Untracked files:
  (use "git add <file>..." to include in what will be committed)

    bar
    baz
    foo

nothing added to commit but untracked files present (use "git add" to track)


On Sat, Mar 7, 2015 at 9:02 PM, Diego Viola <diego.viola@gmail.com> wrote:
> Sorry, I wanted to say: I know I can git-clone in a empty directory
> and then move the files over to $HOME.
>
> I know I can git init in a non-empty directory. :-)
>
> Thanks,
>
> Diego
>
> On Sat, Mar 7, 2015 at 7:26 PM, Andreas Schwab <schwab@linux-m68k.org> wrote:
>> Diego Viola <diego.viola@gmail.com> writes:
>>
>>> I know I could git-init in a empty directory
>>
>> You can also git init a non-empty directory.
>>
>> Andreas.
>>
>> --
>> Andreas Schwab, schwab@linux-m68k.org
>> GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
>> "And now for something completely different."

```

## Kyle J. McKay, 2015-03-08 02:32

Subject: Re: Please consider adding a -f switch to git-clone (or something similar)
Message-ID: <569EEC82-664C-48A7-990D-BFCDB7D78D16@gmail.com>
URL: https://gitlist.dev/e/569EEC82-664C-48A7-990D-BFCDB7D78D16%40gmail.com
In-Reply-To: <CA+ToGPFSbOjfd5gJg+r-7WkwMB=m=4sOupaZo1WUn+O0bxAAXw@mail.gmail.com>

```
On Mar 7, 2015, at 17:53, Diego Viola wrote:
> Something like this is the scenario I'm talking about:
>
> $ mkdir non-empty-dir
> $ cd non-empty-dir
> $ touch foo bar baz
> $ git clone -f url:user/dotfiles.git .
> $ git status
> On branch master
> Your branch is up-to-date with 'origin/master'.
> Untracked files:
>  (use "git add <file>..." to include in what will be committed)
>
>    bar
>    baz
>    foo
>
> nothing added to commit but untracked files present (use "git add"  
> to track)

Have you considered using an alias?

git config --global alias.irfc \
   '!sh -c '\''git init && git remote add origin "$1" && git fetch &&  
git checkout "${2:-master}"'\'' sh'

(You'll likely have to carefully unwrap that line above.)

Then you get

   git irfc <URL> [<branch>]

where <branch> defaults to master.
So your scenario would become just:



$ mkdir non-empty-dir
$ cd non-empty-dir
$ touch foo bar baz
$ git irfc url:user/dotfiles.git
$ git status
On branch master
Your branch is up-to-date with 'origin/master'.
Untracked files:
  (use "git add <file>..." to include in what will be committed)

    bar
    baz
    foo

nothing added to commit but untracked files present (use "git add" to  
track)


-Kyle

P.S. irfc = init, remote, fetch, checkout.  But do make up a better  
name. :)

```

## Diego Viola, 2015-03-08 18:27

Subject: Re: Please consider adding a -f switch to git-clone (or something similar)
Message-ID: <CA+ToGPFZ3JUZJJch03Cc=r7oRj_CKaBwMFCnG0y8XGT6RJYZ2A@mail.gmail.com>
URL: https://gitlist.dev/e/CA%2BToGPFZ3JUZJJch03Cc%3Dr7oRj_CKaBwMFCnG0y8XGT6RJYZ2A%40mail.gmail.com
In-Reply-To: <569EEC82-664C-48A7-990D-BFCDB7D78D16@gmail.com>

```
Kyle,

Thanks, I suppose that works well enough for my needs. I wasn't aware
that aliases were that flexible in git.

I also have no problem to git-init and do all the other steps manually.

Thanks,

Diego

On Sat, Mar 7, 2015 at 11:32 PM, Kyle J. McKay <mackyle@gmail.com> wrote:
> On Mar 7, 2015, at 17:53, Diego Viola wrote:
>>
>> Something like this is the scenario I'm talking about:
>>
>> $ mkdir non-empty-dir
>> $ cd non-empty-dir
>> $ touch foo bar baz
>> $ git clone -f url:user/dotfiles.git .
>> $ git status
>> On branch master
>> Your branch is up-to-date with 'origin/master'.
>> Untracked files:
>>  (use "git add <file>..." to include in what will be committed)
>>
>>    bar
>>    baz
>>    foo
>>
>> nothing added to commit but untracked files present (use "git add" to
>> track)
>
>
> Have you considered using an alias?
>
> git config --global alias.irfc \
>   '!sh -c '\''git init && git remote add origin "$1" && git fetch && git
> checkout "${2:-master}"'\'' sh'
>
> (You'll likely have to carefully unwrap that line above.)
>
> Then you get
>
>   git irfc <URL> [<branch>]
>
> where <branch> defaults to master.
> So your scenario would become just:
>
>
>
> $ mkdir non-empty-dir
> $ cd non-empty-dir
> $ touch foo bar baz
> $ git irfc url:user/dotfiles.git
> $ git status
> On branch master
> Your branch is up-to-date with 'origin/master'.
> Untracked files:
>  (use "git add <file>..." to include in what will be committed)
>
>    bar
>    baz
>    foo
>
> nothing added to commit but untracked files present (use "git add" to track)
>
>
> -Kyle
>
> P.S. irfc = init, remote, fetch, checkout.  But do make up a better name. :)

```
