3

I want to create an alias that looks something like this:

alias getres="git clone https://github.com/user/"

The goal is that i can type "getres repository name" and get the the repository.

However as it stands now,

typing "getres repository name"

Gives me an error saying the repostiory can't be found.

mrmagin
  • 61
  • 1
  • 7
  • 1
    Add `echo` in front of the `git clone` command so that it outputs the commands it wants to execute instead of executing it, then tweak it until it produces the right command. Most likely the parameters are not used. – Lasse V. Karlsen Nov 24 '18 at 22:28
  • 1
    You want a shell function for this, `getres() { git clone https://github.com/user/$*; }` – jthill Nov 24 '18 at 22:38

3 Answers3

3

This happens because getres repository name gets translated to:

git clone https://github.com/user/ repository name

which means you have a space character between https://github.com/user/ and repository name which completely mess with your URL.

The solution for your problem is to create a bash script which accepts 1 parameter (the repository name) then use that script in your alias.

see Make a Bash alias that takes a parameter?

Adrian
  • 3,321
  • 2
  • 29
  • 46
3

What you're after is just a bit beyond the reach of aliases, which are good only for the simplest cases. You want a shell function for this, getres() { git clone https://github.com/user/$*; }

jthill
  • 55,082
  • 5
  • 77
  • 137
0

I have just had this same problem.

For users using zsh / oh-my-zsh / iterm2 (1,2,3)

I updated my .zshrc file with the following:

function getrep(){
    git clone https://github.com/USERNAME/$1.git
}

I added the ".git" at the end because I'm lazy.

Use case is just "getrep REPNAME" from the terminal to clone into whatever current folder you are using.

(1) https://www.zsh.org/

(2) https://ohmyz.sh/

(3) https://iterm2.com/

Joshua Jones
  • 81
  • 1
  • 2
  • 10