Skip to content

Instantly share code, notes, and snippets.

@Kukunin
Created November 3, 2017 09:02

Revisions

  1. Kukunin created this gist Nov 3, 2017.
    17 changes: 17 additions & 0 deletions push_git_to_server.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,17 @@
    # We are in a folder with local git repository
    pwd

    # We need to create an empty repo on the server
    # We want to checkout another branch because
    # git prevents you from pushing to the current checked branch, which is master by default
    ssh <user>@<host> 'mkdir repo && cd repo && git init && git checkout -b local'

    # Add remote repo
    git remote add server <user>@<host>:repo
    # Push master or whatever you want
    git push server master

    # Updates files tree to match your pushed branch
    ssh <user>@<host> 'cd repo && git reset --hard master'

    # That's it. You have a copy of git repository on the server without any intermediate repository