$ 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
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.
So I made a small web app based off of the Angular-Seed project on my local machine. I cloned it from Github and made the project, no problem.
I added all the files/directories without issue, after I deleted the .git directory and .gitignore file from the angular-seed root directory. Running a git status the console reads:
On branch master
Your branch is up-to-date with 'origin/master'.
nothing to commit, working directory clean
However when I add, commit and push to my remote repository, the angular-seed directory (along with the rest of the project files) does not show up.
The directory map looks like /home/user/my-local-repo/angular-seed/ where all the project files are in the angular-seed directory. Can somebody please help me?
git clone --depth=1 {angular seed repo link} mynewproject
cd mynewproject
rm -rf .git
git init
git remote add origin {repo link}
source: https://github.com/angular/angular-seed/issues/239
You might then get a src refspec error, one solution for that is:
Maybe you just need to commit. I ran into this when I did:
mkdir repo && cd repo
git remote add origin /path/to/origin.git
git add .
Oops! Never committed!
git push -u origin master
error: src refspec master does not match any.
All I had to do was:
git commit -m 'initial commit'
git push origin master
Success!
source: src refspec master does not match any when pushing commits in git
Removing the directory from git and adding it again, like this:
git rm --cached directory
git add directory
Source:
Git: fatal: Pathspec is in submodule
I have set up a live repo on my server with:
/cd/siteusername/public_html/
mkdir site.git
cd site.git
git init —bare
cd hooks
cat > post-receive
#!/bin/sh
git --work-tree=/var/www/domain.com --git-dir=/var/repo/site.git checkout -f
chmod +x post-receive
The issue is everytime i push changes from my local repo using:
git add .
git commit -m "file change"
git push live master
git changes the ownership of all the files in my live repo so i get presented with a 500 error
How can i prevent this happening?
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 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