Reputation: 161
I'm working on a Chef project so I ran berks cookbook myproject
on my laptop. I then ran git init
, git add -A
, and then git commit
so that the project is in my local Git repository. Now I want to push it to the central server that my team uses and add it.
I ran git remote add baseLauncher [email protected]:myteam/baseLauncher.git
which produced no output. So I thought it worked fine.
Then I ran git push
, but I got the following error.
fatal: No configured push destination. Either specify the URL from the command-line or configure a remote repository using
git remote add <name> <url>
and then push using the remote name
git push <name>
But that's exactly what I did. I tried searching the git help (useless) and googling for anything on doing this but all of the search returns seemed only to be devoted to 1). How to pull a remote repository 2). How to branch 3). Setting up a central repository that other users will use.
Any ideas on how to do this?
I should note that I'm trying to create the repo on the remote server using the command line. And that the repo has to go "under" my team's git user name.
Just to be clear, this git server is a host on the network of the company I work for. I've just been assigned a new project and I wanted to be able to create the repo for this new project on the server remotely. I assumed that there would be a git command that would enable me to do that.
Upvotes: 1
Views: 466
Reputation: 161
This just popped up when I was browsing our Git repository and clicked on one of our repository links. Apparently it doesn't exist yet because I got this as a response:
Create a new repository on the command line
touch README.md
git init
git add README.md
git commit -m "first commit"
git remote add origin [email protected]:MyWorkgroup/project-cd.git
git push -u origin master
Push an existing repository from the command line
git remote add origin [email protected]:MyWorkgroup/project-cd.git
git push -u origin master
Upvotes: 0
Reputation: 947
I wrote an article that outlines the entire process as I've learned and implemented it, check it out for full details: HOW TO SETUP “PUSH-TO-GIT” DEPLOYMENT WITH SSH
SETTING UP THE SERVER
Change directory to project root
cd public_html/project
Setup repository location and move to that directory
mkdir -p project-name.git
cd project-name.git
Setup up a bare git instance
git init --bare
Setup a post-receive hook for deployment for when a push is made.
touch hooks/post-receive
//create hook
chmod a+x hooks/post-receive
//make hook exectuable
It is one thing to push code to a remote, like github, but in this case when you push commits to this remote you will then want to checkout the files in order for them to actually deploy and we will be doing that in this hook.
#!/bin/bash
# 1. Read STDIN (Format: "from_commit to_commit branch_name")
while read oldrev newrev refname
do
branch=$(git rev-parse --symbolic --abbrev-ref $refname)
if [ "production" == "$branch" ]; then
`GIT_WORK_TREE=../production git checkout -f production`
echo "Changes deployed to live site'"
fi
if [ "stage" == "$branch" ]; then
`GIT_WORK_TREE=../stage git checkout -f stage`
echo "Changes deployed to stage site'"
fi
if [ "development" == "$branch" ]; then
`GIT_WORK_TREE=../dev git checkout -f development`
echo "Changes deployed to development site'"
fi
done
This script is triggered whenever a push is made to this remote server. Many things can happen here, but in this example it simply receives the changes from the branches that are pushed (could be a single branch, could be --all). It then determines which branch was pushed and checkouts the changes to defined directory (GIT_WORK_TREE). The branches and directories must match your structure so make sure to change as necessary. Most development teams will at most have a development environment for testing code, a staging environment for stable releases for client review, and obviously a production environment for the live site.
OR if you prefer no branch management (setting up a git bare repository for each directory [production, staging, development] (this is what I do) and instead use this script
#!/bin/bash
# 1. Read STDIN (Format: "from_commit to_commit branch_name")
while read oldrev newrev refname
do
`GIT_WORK_TREE=../ git checkout -f master`
echo "Changes deployed to {environment}"
done
So you see the beauty of this is when a team of developers commits code they can easily git push <remote> <branch>
and their changes will automatically be deployed (pushed and checked out) to the respective environment.
Upvotes: 1
Reputation: 175007
Git is a distributed version control system or DVCS, this means that no one repository has any more significance than any of the others. For that reason, you cannot create a repo remotely and must be on the machine you're creating the repo at (via SSH, etc).
Creating the repo on a remote location is a relatively straightforward process.
It involves creating the repo with git init
just like you'd do on your local machine (except you'll be SSHing on the remote machine), and using the --bare
tag to ensure on git objects are in the repository (and not an actual working directory with actual code, you don't need it since it's not a development machine)
Assuming no special software (like Stash or GitHub), you'll need to SSH into the machine, and create a bare repo with git init --bare
into a directory you want.
So
$> ssh [email protected]
$> git init --bare myteam/baseLauncher.git
Upvotes: 0