Skip to content

Create git open command#

This command will open the current repo in the browser

  1. Create a bin folder in user profile directory

    1
    2
    3
    4
    ``` bash
    cd ~
    mkdir bin
    ```
    
  2. Add bin to your PATH

    1
    2
    3
    ``` bash
    vim ~/.bash_profile
    ```
    
  3. Inside .bash_profile Add

    1
    2
    3
    ``` bash
    export PATH=~/bin:$PATH
    ```
    
  4. Navigate to bin folder and create a new file called git-open. Note, omit the .sh from the file name

    1
    2
    3
    4
    ``` bash
    cd ~/bin
    vim git-open
    ```
    
  5. Add the following code to git-open

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    ``` bash
    #!/bin/bash
    
    isGitRepo=`git rev-parse --is-inside-work-tree`
    
    if [ 'true' != "$isGitRepo" ]; then
            exit 1
    fi
    
    start='cmd.exe /c start'
    
    remote=`git remote get-url origin`
    url="${remote/ssh/https}"
    url="${url/:22/}"
    $start $url;
    ```
    
  6. Give new git-open script excute

    1
    2
    3
    4
    ``` bash
    cd ~/bin
    chmod +x git-open
    ```
    

Now you can run the script using git open command.


Last update: 2022-02-12 16:09:48