Skip to content

Instantly share code, notes, and snippets.

@Kukunin
Created November 3, 2017 09:02
Show Gist options
  • Save Kukunin/20fa8a00d4ab75aa4366cc1f45fcf3b0 to your computer and use it in GitHub Desktop.
Save Kukunin/20fa8a00d4ab75aa4366cc1f45fcf3b0 to your computer and use it in GitHub Desktop.
How to upload git repo to the server directly without a intermediate repository
# 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment