Skip to content

Instantly share code, notes, and snippets.

@dersam
Last active May 28, 2024 22:14
Show Gist options
  • Save dersam/0ec781e8fe552521945671870344147b to your computer and use it in GitHub Desktop.
Save dersam/0ec781e8fe552521945671870344147b to your computer and use it in GitHub Desktop.
Open GitKraken using the current repo directory in the cli.
## Open GitKraken using the current repo directory.
## For when you want a prettier view of your current repo,
## but prefer staying in the cli for most things.
## This will break if GitKraken ever removes the -p flag.
## If you're not using OSX, the path is definitely different.
kraken () {
~/Applications/GitKraken.app/Contents/MacOS/GitKraken -p $(pwd)
}
# If you want a git alias, add the following to your git config under [alias]
kraken = !"~/Applications/GitKraken.app/Contents/MacOS/GitKraken -p $(pwd)"
# Now you can 'git kraken'!
@mattsson
Copy link

mattsson commented Oct 3, 2019

Are these still working for you when GitKraken is already running? All that happens here is that GitKraken becomes the active window, but no repo is opened. It works fine if GitKraken is not running when I invoke the command.

@skywinder
Copy link

Thanks for this, I was able to take this one step further:

alias kraken="open -a 'GitKraken' --args -p $(pwd)"

  • this will preserve one indow, but works only for one repo. It will not open new repos.

This will keep it from "running" in the terminal, and if you want to be able to spawn multiple instances (to have multiple side by side repos open), add and 'n':
alias kraken="open -na 'GitKraken' --args -p $(pwd)"

  • this opens a new kraken instance for each repo.

Is there any solution to open new repo in new tab of same instance?

@skywinder
Copy link

skywinder commented Dec 30, 2019

Update:
in order to support spaces in the path, wrap double quotes around:

here is a single line to add kraken suppoet in .zshrc:

# Now you can 'git kraken'!
alias kraken='open -na "GitKraken" --args -p "$(git rev-parse --show-toplevel)"'

https://gist.github.com/skywinder/39d4d0708d291f40a97d45e82653f127

@skywinder
Copy link

in the gist is typo with function path.
here is right version

kraken () {
	/Applications/GitKraken.app/Contents/MacOS/GitKraken -p "$(git rev-parse --show-toplevel)" &>/dev/null &
}

@skywinder
Copy link

Both of version got an issue with path renderings. here is my updated version, btw
https://gist.github.com/skywinder/39d4d0708d291f40a97d45e82653f127

Enjoy!

@eengstrom
Copy link

eengstrom commented Jul 27, 2020

I happened to typo this and found a workaround that works with GitKraken 7.1.0 - I added a blank ('', but can be anything) argument before the -p 'PATH'. I'm going to guess it has to do with argument parsing that GK is doing and they are stripping too many arguments before beginning parsing. My current git alias:

kraken = !open -na "GitKraken" --args '' -p "$(cd "${1:-.}" && git rev-parse --show-toplevel) && open -a GitKraken; :"

@d34dman
Copy link

d34dman commented Aug 24, 2020

Thanks @karlwilbur, but one small gripe: this doesn't work for paths with spaces. This works, however:

alias kraken='eval "gitkraken --new-window -p \"`pwd`\" -l /dev/null >/dev/null 2>&1 &"'

A small tweak in the end to bring GitKraken window on Focus

# Open GitKraken using the current repo directory in the cli and bring it on focus.
alias kraken='eval "gitkraken --new-window -p \"`pwd`\" -l /dev/null >/dev/null 2>&1 &" && eval "wmctrl -R GitKraken"'
# Now you can 'kraken'!

@hlynbech
Copy link

hlynbech commented Sep 14, 2020

The new url schema works better for me, I couldn't get any suggestions above to work with GitKraken 7.3.2.

So the idea is that GitKraken automatically installs an URI-schema handler in MacOS that handles URIs that start with gitkraken://

From the docs I learned that the first path component is a directive, so opening a repo is just the directive "repo", so if I have my repo at "/Users/myuser/git/InterestingGitRepo", the terminal command is plainly

open gitkraken://repo/Users/myuser/git/InterestingGitRepo

which opens my repo in a new tab in GitKraken.

So in terms of the aliases in this thread, you could use this:

# Open GitKraken using the current repo directory in the cli and bring it on focus.
alias kraken='open gitkraken://repo/$PWD' 

@eengstrom
Copy link

Thanks @hlynbech for that tip - I totally missed the gitkraken:// scheme. I've updated my ~/.gitconfig with the following:

[alias]
    kraken = !open "gitkraken://repo$(cd "${1:-.}" && git rev-parse --show-toplevel); :"

Note that it works regardless of the directory you are in, even if some subdir within your clone, and allows you to specify some other directory on the command line.

@yi-mei-wang
Copy link

Thanks @hlynbech! I've tried a few things from this thread and yours was the only one that worked for me.

In case anyone coming from Google is wondering, I'm using MacOS Mojave and Zsh.

@weitzman
Copy link

Yes, @hlynbech url scheme approach is working here too.

@eengstrom
Copy link

eengstrom commented Apr 12, 2021

Slight update for anyone who cares - if you happen to have a subrepo or other git-repo inside of another repo this requires a slight fix to use the current working directory instead of just the root of the current repository, so this is my current alias:

  kraken = !open "gitkraken://repo$(cd "${GIT_PREFIX:-.}/${1:-.}" && git rev-parse --show-toplevel); :"

@jorahood
Copy link

jorahood commented Aug 31, 2021

I liked Sourcetree's stree foo on Mac. Similarly krak opens a repo dir passed as arg:

krak () {
    dir="$(cd "$(dirname "$1")"; pwd -P)/$(basename "$1")"
    open gitkraken://repo/$dir
    }

@pablogs9
Copy link

Is there any way to open a folder in an already open instance of Gitkraken? I'm on Linux

@Mayurifag
Copy link

Mayurifag commented Nov 30, 2021

I've ended up with this zsh alias, but, I guess, that would work elsewhere:

alias gk='(eval "gitkraken --new-window -p \"$(git rev-parse --show-toplevel)\" -l /dev/null >/dev/null 2>&1 &")'

It's based on solution from older commends, but:

  • It uses ( and ) to hide the printing of PID process, thats printed by kernel if you use & — thats why I decided to write the comment.
  • It uses --new-window to open repo, if gitkraken already launched somewhere.
  • It uses git rev-parse --show-toplevel and not pwd to get repository right
  • It uses black magic -l /dev/null >/dev/null 2>&1 & to hide all the shit and logs.

@pablogs9 use --new-window. Yea, it's not that obvious.

@pablogs9
Copy link

pablogs9 commented Dec 1, 2021

--new-window works like charm!

@jebeaudet
Copy link

I added this to my .bashrc and it works like a charm in any directory inside a git repo you might be

function kraken() {
  open -na 'GitKraken' --args -p $(git rev-parse --absolute-git-dir)
}

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