Git clone ssh linux

git clone through ssh

I executed the clone but did not print any answer. I logged on to the server machine and tried to see how the files are stored. The path /GitRepos was empty, so I decided to do the clone again:

$ git clone --bare myproject ssh://user@server:/GitRepos/myproject.git 

fatal: destination path ‘ssh://user@server:/GitRepos/myproject.git’ already exists and is not an empty directory.

For me, the ssh:// created a folder, instead of using a remote protocol. Got things to work using @alec-the-geek’s answer. Would you mind selecting a preferred answer for this — it’s your job.

@akauppi: It is the OP’s responsibility to consider all answers, but they are under no obligation to select an answer till they are satisfied. (Of course, it doesn’t hurt to remind them or ask what further info they need for an answer to be acceptable to them!)

10 Answers 10

This is possibly unrelated directly to the question; but one mistake I just made myself, and I see in the OP, is the URL specification ssh://user@server:/GitRepos/myproject.git — namely, you have both a colon : , and a forward slash / after it signifying an absolute path.

I then found Git clone, ssh: Could not resolve hostname – git , development – Nicolas Kuttler (as that was the error I was getting, on git version 1.7.9.5), noting:

The problem with the command I used initially was that I tried to use an scp-like syntax.

. which was also my problem! So basically in git with ssh , you either use

  • ssh://username@host.xz/absolute/path/to/repo.git/ — just a forward slash for absolute path on server
  • username@host.xz:relative/path/to/repo.git/ — just a colon (it mustn’t have the ssh:// for relative path on server (relative to home dir of username on server machine)

This doesn’t work. If you want to specify a relative path with ssh, you have to lose the ssh:// prefix. I just spent 20 minutes trying to figure this out. git clone username@host.xz:relative/path/to/repo.git/ should work.

Tried it with git 2.1.4 on a Debian 8. Either sugestions do not work. No directory was created under /GitRepos on first attempt, and on 2nd attempt complained that the path already existed. Just like the original problem reported

Because of your comment @bobbaluba (and and the updated answer), I didn’t have to spend 20 minutes on this too. Thanks!

For repositories on GitHub, try:

git clone ssh://git@github.com//.git 

For setting up git to clone via ssh see:

is the my username in github or my email address for the github? becaause this link suggests me to use the email address during the public key generation. help.github.com/en/github/authenticating-to-github/… after trying that (empty passphrase for the ssh key gen), I still could not clone repo from github. p.s. I did not add the key to the agent.

same works for gitlab also. prior to that, we need to enable the SSH key setup, as you have suggested

Читайте также:  Поворот экрана linux при загрузке

You need to run the clone command on what you are calling the server. But I bet you are not running an ssh server on your local client so that won’t work anyway. Suggest you follow this approach (check the manual ’cause I’m doing this from memory)

  1. Log into the server machine.
  2. Create a bare repo using git init —bare
  3. On the client machine you can push your repo to the server. git remote add origin ssh://user@server:/GitRepos/myproject.git followed by git push origin master

Great advice! Some notes for newcomers (like me) who haven’t dealt with pure-server-git-folders before: 2. cd /GitRepos; mkdir myproject.git; cd myproject.git before the git init —bare. You won’t get a work copy here — the repo files and folders (normally in .git) will be bare out for you, thus the name of the flag. Thanks

«git init —bare» does not create a .git directory. It puts the files directly on the folder. When adding the remote origin I get : «»fatal: Not a git repository (or any parent up to mount point /home) Stopping at filesystem boundary (GIT_DISCOVERY_ACROSS_FILESYSTEM not set).

Disclaimer: This is just a copy of a comment by bobbaluba made more visible for future visitors. It helped me more than any other answer.

You have to drop the ssh:// prefix when using git clone as an example

git clone git@github.com:owner/repo.git 

Easy way to do this issue
try this.

enter image description here

enter image description here

(using enter key for default value) Step 3: To setup config file

vim /c/Users/Willie/.ssh/config 

Host gitlab.com
HostName gitlab.com
User git
IdentityFile ~/.ssh/id_rsa

git clone git@gitlab.com:/test2.git 

enter image description here

enter image description here

Step 5:
When you finished Step 4
1.the test2.git file will be download done
2.you will get the new file(known_hosts) in the ~/.ssh

PS: I create the id_rsa and id_rsa.ub by meself and I deliver it to the Gitlab server. using both keys to any client-sides(windows and Linux).

git is a decentralized version control system. You do not necessary need a server to get up and running with git. Still you might want to do that as it looks cool, right? (It’s also useful if you want to work on a single project from multiple computers.)

So to get a «server» running you need to run git init —bare .git as this will create an empty repository, which you can then import on your machines without having to muck around in config files in your .git dir.

After this you could clone the repo on your clients as it is supposed to work, but I found that some clients (namely git-gui ) will fail to clone a repo that is completely empty. To work around this you need to run cd .git && touch && git add && git commit && git push origin master . (Note that you might need to configure your username and email for that machine’s git if you hadn’t done so in the past. The actual commands to run will be in the error message you get so I’ll just omit them.)

Читайте также:  Установка линукс через командную строку

So at this point you can clone the repository to any machine simply by running git clone @:.git . (As others have pointed out you might need to prefix it with ssh:// if you use the absolute path.) This assumes that you can already log in from your client to the server. (You’ll also get bonus points for setting up a config file and keys for ssh , if you intend to push a lot of stuff to the remote server.)

Источник

Saved searches

Use saved searches to filter your results more quickly

You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.

Git clone illustration

The git clone command is used to create a copy of a specific repository or branch within a repository.

Git is a distributed version control system. Maximize the advantages of a full repository on your own machine by cloning.

git clone https://github.com/github/training-kit.git

When you clone a repository, you don’t get one file, like you may in other centralized version control systems. By cloning with Git, you get the entire repository — all files, all branches, and all commits.

Cloning a repository is typically only done once, at the beginning of your interaction with a project. Once a repository already exists on a remote, like on GitHub, then you would clone that repository so you could interact with it locally. Once you have cloned a repository, you won’t need to clone it again to do regular development.

The ability to work with the entire repository means that all developers can work more freely. Without being limited by which files you can work on, you can work on a feature branch to make changes safely. Then, you can:

  • later use git push to share your branch with the remote repository
  • open a pull request to compare the changes with your collaborators
  • test and deploy as needed from the branch
  • merge into the main branch.

Common usages and options for git clone

  • git clone [url] : Clone (download) a repository that already exists on GitHub, including all of the files, branches, and commits.
  • git clone —mirror : Clone a repository but without the ability to edit any of the files. This includes the refs, or branches. You may want to use this if you are trying to create a secondary copy of a repository on a separate remote and you want to match all of the branches. This may occur during configuration using a new remote for your Git hosting, or when using Git during automated testing.
  • git clone —single-branch : Clone only a single branch
  • git clone —sparse : Instead of populating the working directory with all of the files in the current commit recursively, only populate the files present in the root directory. This could help with performance when cloning large repositories with many directories and sub-directories.
  • `git clone —recurse-submodules[=

You can see all of the many options with git clone in git-scm’s documentation.

The most common usage of cloning is to simply clone a repository. This is only done once, when you begin working on a project, and would follow the syntax of git clone [url] .

git clone —single-branch : By default, git clone will create remote tracking branches for all of the branches currently present in the remote which is being cloned. The only local branch that is created is the default branch.

But, maybe for some reason you would like to only get a remote tracking branch for one specific branch, or clone one branch which isn’t the default branch. Both of these things happen when you use —single-branch with git clone .

This will create a clone that only has commits included in the current line of history. This means no other branches will be cloned. You can specify a certain branch to clone, but the default branch, usually main , will be selected by default.

To clone one specific branch, use:

git clone [url] —branch [branch] —single-branch

Cloning only one branch does not add any benefits unless the repository is very large and contains binary files that slow down the performance of the repository. The recommended solution is to optimize the performance of the repository before relying on single branch cloning strategies.

Depending on how you authenticate with the remote server, you may choose to clone using SSH.

If you choose to clone with SSH, you would use a specific SSH path for the repository instead of a URL. Typically, developers are authenticated with SSH from the machine level. This means that you would probably clone with HTTPS or with SSH — not a mix of both for your repositories.

  • git branch : This shows the existing branches in your local repository. You can also use git branch [banch-name] to create a branch from your current location, or git branch —all to see all branches, both the local ones on your machine, and the remote tracking branches stored from the last git pull or git fetch from the remote.
  • git pull : Updates your current local working branch with all new commits from the corresponding remote branch on GitHub. git pull is a combination of git fetch and git merge .
  • git push : Uploads all local branch commits to the remote.
  • git remote -v : Show the associated remote repositories and their stored name, like origin .

Get started with git and GitHub

Review code, manage projects, and build software alongside 40 million developers.

Источник

Оцените статью
Adblock
detector