How to add a git repository to Ubuntu server - node.js

I have a node.js project local in my computer, right now, I want to push this project to remote Ubuntu server. I have create a project.git on Ubuntu server, and pushed to it. Right now, I want to run this project on the server, but how do I access this folder, it's just a git directory. The process I am following is like below:
Ubuntu server:
mkdir /home/git/project
cd /home/git/project
git init
Local computer:
git remote add origin root#someserver.com:/home/git/project
git add .
git commit -am "Initial Commit"
git push origin master
It push succeed. Right now, I want to execute this node.js project and run it on the server, but how to turn this git repository to a folder, so I can cd into it and then node app.js after?

If you want to see the code on the server side, you should init the repository without --bare option or clone it somewhere else on the server.
Bare repositories store only git specific files.
UPDATE:
If you create a repository without --bare option, you can't push anything to that branch where your server is staying. Better solution is if you create a bare repository and clone it somewhere else on the server. Notice that, you should use there git pull command if you want to see your fresh code.

Related

How can I connect to a git repository and work from it remotely cross-platform?

I am trying to build an update sequence for my game server. I am using git to host my file platform changes since it is capable of merging.
First, I want to create a repository and upload it to my git account as a 'fresh install'.
git init
git remote add origin https://github.com/...
git add "RV SERVER"
git commit -m "Initial upload"
git push
This now uploads my server from my development PC. I now want to download the git repository on my VPS via SSH.
git init
git remote add origin https://github.com/...
git pull
Then when I want to update the server files with any new player saves I use this
git init
git remote add origin https://github.com/...
git commit -m "Merge for any player save updates"
git push
However, I get the error that there is a pull request waiting (which is the update) however, I want to first save the player information so it merges with the new update and then download any file updates.
How can I do this?

How do I keep a git clone updated?

I am developing a project on my laptop that is to be implemented on my VPS. I am continually making updates on my laptop and pushing them to my git repo, but I am in the dark on how I should keep the clone I made on my server, updated.
When I try to run git clone <url> in my directory, it tells me 'file already exists!' or something along those lines. Do I just delete the entire folder and reclone the repo like that? Or is there a way, other than initiating the directory as git, and creating an upstream, that I can reclone without having to delete everything first?
How do I keep a git clone updated?
I generally clone git project.
git clone git#source.golabs.io:mobile/project-name.git
and after that I start developing my feature by creating new branch branch.
so for up to date with remote project you need to checkout to master branch. and just do
git pull and sync your project using ./gradlew clean build
If your project have submodules- you need to do
git submodule update --init --remote --recursive
try to use git pull. it will automaticly analyze the difference .And try to fix it
Instead of having to go to your server and pulling, you could setup a listener in order to do the pull for you.
For instance, if you are ushing to GitHub or BitBucket or GitLab, you can setup a webhook (GitHub webhook, BitBucket webhook, GitLab webhook), and a local listener in order detect the push, and triggger a git -C /path/to/your/repo pull.

Can't find my git repository url

So I think I am confused - but for some reason I cannot push or pull to my git repository.
I have a linux web server and have a web folder in /var/www/bcs.net.nz/
I did a git init bcs.git in this folder (I have also tried .git)
and then I thought I could do git clone git#bcs.net.nz:bcs.git to clone it on the local machine or git push on the remote machine.
I have also added a git remote add origin git#bcs.net.nz:bcs.git on the remote machine.
After all of that I still cannot push and pull anything.
I am a bit stuck.
git add . & git commit -m "initial commit" work fine.
git clone git#bcs.net.nz:bcs.git would mean to clone a (preferably bare repo) which is in /home/git/bcs.git
You could initialize one there, (git init --bare /home/git/bcs.git), and add a post-receive hook (chmod 755 /home/git/bcs.git/hooks/post-receive) which will checkout the code in the live server folder
#!/bin/sh
git --work-tree=/var/www/bcs.net.nz --git-dir=/home/git/bcs.git checkout -f

Added BitBucket repo as remote on GitHub

I've just installed git on Ubuntu, now I want to work on my repo in BitBucket. I'm a little confused on how to do so. I can't do the following:
git remote add BitBucketRepo git#bitbucket.org:dir/file.git
As it returns the following error:
fatal: Not a git repository (or any of the parent directories): .git
It clearly is pointing to a git repo, so why is it lying to me?
Also, it is worth noting I am using SSH and I have successfully paired my GitHub account to my computer.
You need to run this command from a local git repository (a directory in which you have run git init or git clone) - otherwise git remote doesn't know which local repo you want to add the remote for.
It should be as simple as cd my-local-dir, where my-local-dir is the directory containing your local (cloned) git repository.
If you don't yet have the repo available locally:
git clone git#github.com:...etc... my-local-dir
cd my-local-dir
git remote add ButbucketRepo git#bitbucket.org...
git push -u ButbucketRepo master
This will clone your code from Github into the my-local-dir directory, add your BitBucket repo as a remote repository, push your code up to Bitbucket and set the local master branch to track the BitBucket remote's master branch.
Tracking means that commands that involve a remote like git push will automatically use the BitBucket remote's master branch. If you don't want that behaviour, skip the -u option.

git post-receive checkout to remote machine?

If you add the following script as a hooks/post-receive hook to a bare git repository foo.git:
#!/bin/sh
GIT_WORK_TREE=/bar git checkout -f
then whenever someone pushes to the repository the current state will be updated in directory bar.
This requires bar and foo.git to be on the same machine.
What's the easiest way to modify it so that the checkout is made on a remote machine (say baz:/bar) ?
One way would be to:
#!/bin/sh
GIT_WORK_TREE=/tmp/bar git checkout -f
rsync ... /tmp/bar baz:/bar
Is there a better way? Perhaps not requiring an intermediate temp directory? (If not what are the correct options to pass to rsync such that the resulting directory is indentical to being checked out directly?)
GIT_WORK_TREE=/bar means that bar is a git repo.
If bar is a git repo on the remote side, then it can pull from a bare repo bare_bar.git (also on the remote side), to which you can push to.
In other words, your post-receive hook would push to bare_bar repo through ssh, and a post-receive hook on that bare repo would trigger the pull from the actual repo bar: see "Creating a git repository from a production folder".
I'd prefer a solution that keeps the remote server free of any .git dirs (and even the git package itself ideally)
In that case, your current post-receive hook and its rsync command seems to be the only way to incrementally copy new data to a remote working tree.
git archive would archive everything each time.
git bundle would require git on the other side.

Resources