Skip to content
This repository has been archived by the owner on Nov 25, 2022. It is now read-only.

Add combination command to git clone and cd into directory #111

Open
salcode opened this issue Jan 13, 2020 · 2 comments
Open

Add combination command to git clone and cd into directory #111

salcode opened this issue Jan 13, 2020 · 2 comments

Comments

@salcode
Copy link
Member

salcode commented Jan 13, 2020

Every time I do git clone, I follow it with cd to move into the project directory.

e.g.

git clone git@github.com:ironcodestudio/ironcode-git-enhancements.git
cd ironcode-git-enhancements

It would be nice to combine these.

Hat Tip to @michealengland

@salcode
Copy link
Member Author

salcode commented Jan 13, 2020

See StackOverflow git clone and cd into it

@salcode
Copy link
Member Author

salcode commented Jan 20, 2020

Right now, adding this to bash_profile-mods.bash seems to be the best I've come up with

function gitclonecd() {
	if [[ $1 =~ /(.*)\.git$  ]]; then
		echo ${BASH_REMATCH[1]};
		git clone $1;
		cd ${BASH_REMATCH[1]};
	else
		echo "Could not derive a valid directory name from repository.";
	fi;
}

This allows

gitclonecd git@github.com:ironcodestudio/ironcode-git-enhancements.git
# which clones the repo and then does a cd into it

I've been unable to make this a Git alias (and have made it a bash alias) because I am unable to change the working directory from within the git alias.

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

No branches or pull requests

1 participant