Quickly navigate to your GitHub repositories.
Without gitcd
, you may need to manage multiple GitHub repo clones manually:
mkdir -p ~/github/coollog
cd ~/github/coollog
git clone https://github.com/coollog/gitcd.git
cd gitcd
# Now make some commits.
# Time to work on another repo.
mkdir -p ~/github/foo
git clone -C ~/github/foo/bar https://github.com/foo/bar.git
cd ~/github/foo/bar
# Make some edits.
# Now time to go back to coollog/gitcd. Where is it again? Oh, right.
cd ~/github/coollog/gitcd
# Some days later. Did I clone foo/bar already?
ls ~/github/foo/bar
# Ah okay, time to go work on that.
cd ~/github/foo/bar
...
With gitcd
, this becomes just:
gcd coollog/gitcd # Clones https://github.com/coollog/gitcd.git
# Make some commits.
gcd foo/bar # Clones https://github.com/foo/bar.git
# Make some commits.
gcd gitcd
# Some days later.
gcd bar
...
curl -Lo ./gitcd https://storage.googleapis.com/gitcd/gitcd-linux-amd64 && \
chmod +x ./gitcd && sudo mv ./gitcd /usr/local/bin
curl -Lo ./gitcd https://storage.googleapis.com/gitcd/gitcd-darwin-amd64 && \
chmod +x ./gitcd && sudo mv ./gitcd /usr/local/bin
Download the latest Windows build: https://storage.googleapis.com/gitcd/gitcd-windows-amd64.exe
go get -u github.com/coollog/gitcd
# `gitcd` will be at `$GOPATH/bin/gitcd`
This adds gcd
as a bash
function.
[ -f ~/.bashrc ] && echo 'gcd() { GITCD_GCD=1 gitcd "$@" && cd `gitcd "$@"`; }' >> ~/.bashrc && . ~/.bashrc
[ -f ~/.bash_profile ] && echo 'gcd() { GITCD_GCD=1 gitcd "$@" && cd `gitcd "$@"`; }' >> ~/.bash_profile && . ~/.bash_profile
gcd coollog/gitcd
gitcd
clones the repository first if it does not exist.
Set GITCD_HOME
to change the root directory for the cloned repositories. By default, gitcd
uses ~/gitcd
.
# These all navigate to the directory for the cloned repo, cloning the repo if necessary.
gcd https://github.com/coollog/gitcd.git
gcd https://github.com/coollog/gitcd.git
gcd https://github.com/coollog/gitcd
gcd [email protected]:coollog/gitcd.git
gcd github.com/coollog/gitcd
gcd coollog/gitcd.git
gcd coollog/gitcd
gcd gitcd # If you have used repos under coollog/ before.
# This makes another clone under ~/github2.
GITCD_HOME=~/github2 gcd coollog/gitcd
# This navigates to the directory in your GOPATH.
GITCD_HOME=$GOPATH/src/github.com gcd coollog/gitcd
When the name is ambiguous (just the repo name like gitcd
rather than coollog/gitcd
), gitcd
tries to find the name under owners in the order in which they were last used. For example, if gitcd
had used foo/
, bar/
, and cat/
(in that order), gcd dog
would try to find dog
in cat/dog
, then bar/dog
, then foo/dog
.