I'm new to git, trying to get my head round it.
So I'm developing a simple website locally and tracking it with git and want a remote repo on the public facing server to be the live site, to which I can push the master branch whenever I'm ready to do so.
I thought the following would work but it doesn't.
Public server I did this:
/home/mysite/git init --bare
Local (development machine) I did this:
git init
git add index.html (contains hello world)
git commit -am "initial commit"
git remote add website ssh://mysiteuser@mysite:myport
git remote (outputs: website)
Now I want to publish this to the 'website'
git push website
And I get:
fatal: The current branch master has no upstream branch.
To push the current branch and set the remote as upstream, use
git push --set-upstream website master
So I try:
git push --set-upstream website master
And I get:
fatal: No path specified. See 'man git-pull' for valid url syntax
I looked in man git pull and it sheds no light for me.
Am I doing this right but missing something in the push command? Or have I misunderstood something more fundamental.
TIA!
It's simple and follow the small Steps to proceed:
Now create a project folder $mkdir project.git
$cd project and execute $git init --bare Let's say this project.git folder is present at your ip with address inside home_folder/workspace/project.git, forex- ec2 - /home/ubuntu/workspace/project.git
Now in your local machine, $cd
into the project folder which you want to push to git execute the below commands:
git init .
git remote add origin username@189.14.666.666:/home/ubuntu/workspace/project.git
git add .
git commit -m "Initial commit"
Below is an optional command but found it has been suggested as i was working to setup the same thing
git config --global remote.origin.receivepack "git receive-pack"
git pull origin master
git push origin master
This should work fine and will push the local code to the remote git repository.
To check the remote fetch url, cd project_folder/.git and cat config, this will give the remote url being used for pull and push operations.
You can also use an alternative way, after creating the project.git folder on git, clone the project and copy the entire content into that folder. Commit the changes and it should be the same way. While cloning make sure you have access or the key being is the secret key for the remote server being used for deployment.
I suspect my original question was misunderstood by those good people who tried to help me. To re-iterate - I want to have the development repo locally, and when I 'push' have it automatically update the files on my web server so that the website project is pushed live on my whim.
Here's how I've done it...
ON REMOTE (WEB SERVER)
mkdir website
cd website
git init
// here's the clever bit!
git config receive.denyCurrentBranch updateInstead
(That last line does two things. It stops the remote repository from complaining about an update to the checked out branch - and it also checks it out straight away. Other methods commonly used add a 'hook' to do the latter part of the process.)
ON LOCAL DEVELOPMENT (MY LAPTOP)
cd ~/website-dev-folder
git init
git remote add website ssh://my_user_name@mysever.com:my_port/home/website
git add some_file.html
git commit -m "initial commit"
git push -u website master
Henceforth after any local change is finalised and merged into master, to publish the master branch live it's a simple:
git push
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.