I want to create a deployment server with nodejs application. I'll write nodejs code on my windows machine and push it on that ubuntu linux server. Can you tell how should I setup git for pushing a new code into this one?
Easiest way to setup git on server is to create empty bare git repository on server:
mkdir -p path/to/git/repos/myproject.git
cd path/to/git/repos/myproject.git
git init --bare
Now, go back to Windows box and setup msysgit git command line client or TortoiseGit to connect to your Linux box over ssh.
Your goal is to successfully clone your empty repo from the server:
git clone ssh://username#server:/path/to/git/repos/myproject.git
Once this is done, you can git add your content to directory myproject, then git commit it and finally git push.
Related
I've been trying to push commits created with a simple shell script:
cd $dir
git add . && git commit -m "Test commit" &&
git push --all origin
The script does the job perfectly. Yet Crontab is stuck at making commits locally and Jenkins is getting 'Permission denied' when accessing a local git folder even if I assign Jenkins a group that owns the folder.
I tried Jenkins jobs with Execute shell either with the code or the path to the script. Any help would much appreciated.
One thing to note is that Jenkins goes back to the original workspace to run each command. So when you run cd $dir, the script will switch to $dir, but once you start the git add... command, it will go back to your workspace directory. To prevent this, either chain the commands together:
cd $dir && git add . && git commit -m "Test commit" && git push --all origin
or use dir to wrap the git commands so that they always run in that specific directory.
As advised by #M B summarizing:
Crontab:
For the cron commits to be pushed automatically:
Add a hook file to your git directory:
How can I automatically push after committing in Git?
Jenkins:
To commit and push automatically add a node. I also added to a sudoers file by sudo visudo:
jenkins ALL=(ALL) NOPASSWD: ALL
%sudo ALL=(ALL:ALL) ALL
I have also assigned a safe directory:
git config --global --add safe.directory /path/to/your/git/dir
EDIT: Just tested with Amazon EC2 Plugin, after cloning the repo on an EC2 instance use:
git remote remove origin
git remote add origin https://ghp_TOKEN#github.com/USER/REPO.git
git add . && git commit -m "COMMIT" && git push --all origin
And these 3 also work for Crontab and Terraform (no other settings needed).
Hope this helps.
I want to clone an git repo to an offline VM (Debian). I can ssh into the offline VM via my local machine (Mac) which has internet access. How can I clone a git repo to that offline VM?
Does simply scp the repo folder to the VM directory works? Like:
local_machine$ git clone https://github.com/rstudio/shiny-server.git
local_machine$ scp ~/shiny-server VM_machine:
local_machine$ ssh VM_machine:
VM_machine$ mv ~/shiny-server ~/workspace
Please help.
You can just clone the repository in the VM from your local machine:
VM_machine$ git clone local_machine:~/shiny-server ~/workspace
Reference: The SSH Protocol
Locally I have created a repo with my some file. Then I would like to add this repo (this file) to the repo which is on other server by ssh (on Linux). So on my local machine:
mkdir localRepo && cd /localRepo
git init
touch someFile
git add .
git commit -m "add someFile"
git remote add origin ssh://smith#sam.uf.com/srv/git/hello.git
To check if everyhing go well on local machine I have created a new repo and clone from other machine:
cd .. && mkdir localRepo2 && cd localRepo2
git init
git clone ssh://smith#sam.uf.com/srv/git/hello.git
In the repo in "localRepo2" on local machine there is no file "someFile", but it should be. What I have done wrong?
git remote add origin ssh://smith#sam.uf.com/srv/git/hello.git
only adds a reference to the remote in your local repo. It doesn't push / get any file.
From your localRepo you should push your file to your remote repo
git push origin master
Then to get it from another local repo you could either clone a new local repo now, or go to the localRepo2 and do
git pull origin master
How to mirror my git repository to more notebook at home.
My firm is using SVN for version control so I am using "git svn clone" to clone it and then push it to my git repository on the internet. My new question being new to git is how to I get a computer of the repository on my notebook at home
I do the following at work to clone my work SVC
cd ~/tmp/svn-mirror/
git svn clone http://svn/java mirror.git
cd ~/tmp/svn-mirror/mirror.git/
git remote add origin git#git.xxxx.com:MIRROR.git
git push origin master
Then I run the following script every hour to push it to the git repository on the internet
#!/bin/bash
cd ~/tmp/svn-mirror/mirror.git/
git svn rebase
git push origin maste
Now once I get home. what do I have to do to use the git repository on my notebook.. Please keep in mind I dont know git.. thanks
Have you tried doing a simple git clone?
git clone git#git.xxx.com:MIRROR.git /directory/in/your/notebook
from your notebook?
I have a Git repository on a server and on the same server I have a script which needs to do a git archive of the repository.
Here's my sample git archive command which works well for remote Git repositories:
sudo git archive --remote=ssh://uname#dev.example.com/var/repo/myrepo.git --format=tar --output=src.tar development
What would I need to do/change to execute the aforementioned command on the same server so that I don't need to put all the SSH stuff? Since the command is running on the same machine as the repository, can I get away with directly accessing the Git directory.
Thanks
Use
cd .../yourcode
sudo git archive --format=tar --output=src.tar development
(it is probably unnecessary to sudo)
Sure. Just run git archive from the directory that contains the local repo, and don't specify --remote.
From the directory that is your git repository run:
git archive | bzip2 > full/relative/or/qualified/path/to/place/you/want/to/store/your/archive.tar.bz2