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'!
@sgates
Copy link

sgates commented Jun 23, 2017

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

alias kraken="open -a 'GitKraken' --args -p $(pwd)"
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)"

@kud
Copy link

kud commented Dec 13, 2017

Yes @BBlackwo , however it does two side effects:

1/ You still will see logs in the current terminal (You've got a solution here is to use 2> /dev/null
2/ When you quit Kraken, it's still in background as shell task (I wonder why) and here it takes lots of CPU, I don't know why either

The best way for me is the @sgates ' one.

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

@krenor
Copy link

krenor commented Jan 3, 2018

For me the alias didn't work using zsh due to shell expansion. You'll have to switch the quotes:
alias kraken='open -na "GitKraken" --args -p $(pwd)'

@souhaiebtar
Copy link

@krenor i copied the alias to my .zshrc file but it didn't work

@jsonkao
Copy link

jsonkao commented Feb 12, 2018

@sgates 's solution works for me. I'm using the latest macOS and zsh.

@steezeburger
Copy link

For some reason, when using the alias, if GitKraken is not already open, it freezes my computer for ~10s while it seems to open. Anyone else experiencing this?

@rpardee
Copy link

rpardee commented Aug 29, 2018

Here's a powershell function in case anybody wants:

function krak() {
  $curpath = (get-location).ProviderPath
  $lapd = $env:localappdata
  $logf = "$env:temp\krakstart.log"
  start-process -filepath "$lapd\gitkraken\app-4.0.2\gitkraken.exe" -ArgumentList "--path $curpath" -redirectstandardoutput $logf
}

I get a few node event log entries printed to stdout from that, which is annoying but livable.

@chris-towles
Copy link

chris-towles commented Oct 23, 2018

Thanks @rpardee. A made a small change to the Powershell Function to always use the lastest version of gitkraken.exe

# Open Git Kraken
function krak() {
  $curpath = (get-location).ProviderPath
  $lapd = $env:localappdata
  $logf = "$env:temp\krakstart.log"
  $newestExe =  Get-Item "$lapd\gitkraken\app-*\gitkraken.exe" | select -Last 1
  start-process -filepath   $newestExe -ArgumentList "--path $curpath" -redirectstandardoutput $logf
}

Reminder: if you add this function to %userprofile%\documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1 it will always be in available in your PowerShell console.

@seanhoughton
Copy link

This will always pass the root of the current git repo to GitKraken

alias kraken='open -na "GitKraken" --args -p $(git rev-parse --show-toplevel)'

@frou
Copy link

frou commented Feb 19, 2019

Thanks @seanhoughton . Here's a slight modification so that it will work even if the path has spaces:

alias kraken='open -na GitKraken --args -p "$(git rev-parse --show-toplevel)"'

Note to readers: open(1) is a macOS command.

@karlwilbur
Copy link

For Linux (Ubuntu):

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

@Arm1stice
Copy link

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 &"'

@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