Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gg cl to move inside cloned directory #50

Open
mkody opened this issue Aug 19, 2015 · 3 comments
Open

gg cl to move inside cloned directory #50

mkody opened this issue Aug 19, 2015 · 3 comments

Comments

@mkody
Copy link

mkody commented Aug 19, 2015

When most people use the git clone command, they just directly move inside the directory with cd.

I'm suggesting to make gg cl automatically change the current directory to the cloned repo... or maybe add a new command?

Thanks!

@qw3rtman
Copy link
Owner

This is a great idea! Sadly, AFAIK, there is no way to do this without introducing an external script that changes the directory which you would then source in the main script.

If there is an elegant solution, I would love to have this implemented!

@professorjamesmoriarty
Copy link
Contributor

Taken from http://unix.stackexchange.com/questions/97920/how-to-cd-automatically-after-git-clone

It may be a starting point.

git()
{
   local tmp=$(mktemp)
   local repo_name

   if [ "$1" = clone ] ; then
     /usr/bin/git "$@" | tee $tmp
     repo_name=$(awk -F\' '/Cloning into/ {print $2}' $tmp)
     rm $tmp
     printf "changing to directory %s\n" "$repo_name"
     cd "$repo_name"
   else
     /usr/bin/git "$@"
   fi
}

@qw3rtman
Copy link
Owner

This is essentially creating the directory beforehand and them cloning into that directory, which is a valid solution except the issue we are running into is related to how Shell scripts execute commands.

In a Shell script, a subshell is created. cd will change the directory of the subshell, which is different from the shell that is executing the script (i.e. the user's terminal).

Here's a better explanation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants