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
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.
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
I recently set up a new VPS and have installed Git via yum and wget etc. All seemed well - I can add, commit, set up a remote and push to github.
However, when I try to pull from github:
user#domain.com [~]# git pull github master
git: 'pull' is not a git command. See 'git --help'.
Did you mean this?
shell
No, I didn't mean shell, I meant pull!
Now I've googled the heck outta this - including reading several posts on Stackoverflow:
"git pull" broken
git: 'pull' is not a git command. See 'git --help'
Although most posts seem to be about Mac issues (I'm on a CentOS server), it seems to be an issue with the git exec path, which is
user#domain.com [~]# git --exec-path
/usr/local/libexec/git-core
I've tried adding a various things to .bashrc with no success.
The key thing is that when I cd down to /usr/local/ and ls -l, I can't see a libexec directory.
But if I log in as root, I can cd to /usr/local/ and see libexec/, inside which is git-core. I can also git pull as root.
So - I suspect the problem is more to do with permissions and the server setup than git itself.
I've tried
sudo chmod a+rx /usr/local/libexec
But that did nowt too...
When I ssh into another server, as an account user, I can cd down to /usr/local and see libexec - so there's something wrong with this server setup.
Any ideas gratefully received.
Solved it now - the server is using jailshell... Disabling jailshell and using 'normal' shell works a treat
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.
$ git clone ssh://host/repo.git ~/
destination directory '/home/username/' already exists.
Can anyone tell me how to make this work? I'm trying to quickly be able to replicate common dev scripts and config.
This seems to work:
cd ~
git init
git remote add origin ssh://host/repo.git
git pull origin master
The clone command creates a new directory when you pass a second argument:
$ git clone ssh://host/repo.git ~/your_directory
clone will create ~/your_directory. If the directory already exists it will give you the error you get.
cd ~
git clone ssh://host/repo.git
After that, you have the project in the /home/username/repo/ directory
If you want to have the project in a different folder name (e.g 'foo/')
mkdir ~/foo
cd ~/foo
git clone ssh://host/repo.git foo/
I would clone the repository into a subdirectory:
git clone ssh://your/git/repo.git ~/repo
And create symlinks to the configuration files:
ln -s ~/repo/.bashrc ~/.bashrc