How to get the process when I use ssh to a remote server to git a repository? - linux

I am from China, and for some reason git connect is very slow. I know how to use git proxy, but still not fast.
What I know and tried is to SSH to my VPS and download git repository in my VPS. and then I zip the repository fold and SCP the zip from in my local computer. In this way, finally I get my git repository which it very comfortable for my and it is fast!!!
Now I want to know, is there a simple command or shell to achieve this?
I cant handle it by typing every time but it is not effective.

scp relies on ssh. You can always clone the repository over ssh from your VPS. In one line you could do something like this:
$ ssh <VPS> git clone https://<project.git> && git clone ssh://VPS/<project.git>
Reference

Related

How can I determine the URL my git repo is located?

I am to work on a project and I have initialized a git repo on a server. Let's suppose the URL of the server is
foo.bar
and the repo is at
/var/www/vhosts/foo.bar/httpdocs
I have created a git repo by running
git init
and then I created a .gitignore file, added whatever needed to be added, committed and from my local computer, which has ssh access to the server I have attempted to clone the repo, but I do not seem to find the correct URL or something is not set for the repo. I tried something like:
git clone https://foo.bar/httpdocs/.git
The error was
fatal: repository 'https://foo.bar/httpdocs/.git' not found
I have tried with various pathes.
FYI: I have worked with git a lot in the past, but I have never set up a repository on a server, I have always received the path of repos created by someone else. Now I have created the repo, but I cannot seem to find out what the correct URL is. I have searched a lot to find this out, but unfortunately I did not find anything which would help me. Any ideas?
If you're trying to communicate via SSH, you need the SSH link, not the HTTP(S) link:
git clone <user>#foo.bar:/var/www/vhost/foo.bar/httpdocs/.git
You need git and sshd (or openssh-server) installed on the remote server, and add your SSH key to the server, under the correct user (with ssh-copy-id, of course).
This is pramar error.
The error is in line:
cit clone https://foo.bar/httpdocs/.git
you can try:
git clone https://foo.bar/httpdocs/.git
good luck.

Mercurial like method for creating git remote repository

When I was using Mercurial, creating a remote repository is one command line:
hg clone local remote
Where remote is something accessible via ssh. For instance:
hg clone /path/to/local/repo.hg ssh://host.name/path/to/new/clone.hg
I don't know if it is a functionality in Mercurial or we have installed something to make that possible.
Is there any way to do that with git? Or install something that will allow me to do the same like with Mercurial?
NOTE
My question is not 'How to clone a remote repository?'
No, you can't do that with a single command, and you can't do that using Git alone either.
You roll something like this:
Initialize a repository on the server:
ssh user#server git init --bare /path/to/the/new/repo
Push your local repository there:
git push --all --tags ssh://user#server/path/to/the/new/repo
If you intend to work with that new remote repository (push/fetch) afterwards, it makes sense to add it as a named remote, so your step #2 becomes:
git remote add foo ssh://user#server/path/to/the/new/repo
git push --all --tags foo

Solution for Git GUI client for remote SSH

I am a Git GUI user. I don't have an issue using it for my local development. However, now we have a server with a Git repository. Can I remotely push, pull and diff by using the Git GUI client to access that?
Currently, I am SSHing to the Linux server, and use a Git command to do all the Git commands. But I found it very difficulty when it comes to diff. That's why I think is there any solution for me using the Git GUI client access remote repository and do the Git command with a Git client.
I want to be able to mount a remote server in a Git repository.
Current we only have to open the Git repository in our local disk. For example, the C:\www\repo.git file. How about if I want to access 10.10.10.10/home/www/.git and do all the Git commands in the Git client?
Solutions are open for OS X and Windows.
Aside from VNC / remote X (which is an obvious solution and therefore not worth putting in an answer), the only alternative I can find is Visual Studio Code's new remote development support.
You can connect to a server via ssh (from within Visual Studio Code), and then Visual Studio Code's Git features work natively. The interface is fairly basic however - in particular there is no history view and you can't rebase, cherry-pick, etc. from the GUI. It's basically for staging commits.
This extension gives you a proper git graph view. It's pretty good.
If your server has it enabled, you can use XForwarding to display a GUI executed on the remote machine on your local machine.
On the server-side, this means that you need to have the proper tools installed (e.g., git-gui, which means that you also need Tcl/Tk installed, which means that you also need the X infrastructure installed).
You also must enable Xforwarding, by making sure that you have a line like the following in your /etc/ssh/sshd_config:
X11Forwarding yes
To use that on your local Linux machine, you would usually use the -X flag to enable XForwarding for a given connection:
shiro#local:~$ ssh -X gituser#gitserver
gituser#gitserver:~$ cd repo.git
gituser#gitserver:~/repo.git$ git gui
On your local OS X machine, you would instead use -Y:
shiro#applejoice:~$ ssh -Y gituser#gitserver
gituser#gitserver:~$ cd repo.git
gituser#gitserver:~/repo.git$ git gui
You need an Xserver running on your local machine, in order to use XForwarding. While this is not a problem on Linux (or OS X), it gets complicated for Win32. There are tutorials on the web for setting up and using Xservers under Win32 (e.g., Xming).
First, when it comes to diff, you can simply git fetch your repo, and do the diff locally (with git gui), since you have the all history.
Second, if you have ssh access to the server, you don't need to actually open an ssh session.
A simple git command git#gitserver:/path/to/git/project.git is enough (repalce "command" with clone/push/pull/fetch)
That means the fetch is easy.
See Git on the Server - Setting Up the Server for an ssh setup, at least for Linux or Mac.
For Windows, you have alternative ssh server you can consider, like copssh-free-edition.
But now our team is having this issue, and I am the only person in charge for the GIT. That's why I looks for help how to solve this
Then you would need to ssh to the server, git add and git commit there in the repo, then go back to your local workstation, clone or fetch, and do the diff there. –

How do I clone a git repository located on my Mac connected to the internet?

I have an up-to-date git repo that I started on my MacBook. The project that I am working on is required to work on my university's Linux workstations that I can login to remotely via SSH. I've cded to the directory that I want to clone to on the workstation. I just have no idea how to get the SSH address for the repo on my MacBook when its connected to the internet. Also, how would this stay consistent considering I get a different IP every time I reconnect or go somewhere? Is what I'm doing even possible or a good idea?
One simple solution is to create an empty repository using a free github.com or bitbucket.org account. Using github for this example, you would then have a URL for the repo such as:
https://github.com/username/repo-name.git
Then, simply push the contents of your local repo up to the newly created online repo like so:
$ git remote add origin https://github.com/<username>/repo-name.git
$ git add --all
$ git commit -m 'initial commit'
$ git push -u origin master

Etckeeper + git and remote server

Is it some possible to clone etckeeper git repo on my computer, make some changes and after that push to /etc folder on server?
I tried this but i have problem with push because etc is noa a bare repo.
Thanks for help.
BR,
You would have to either pull repo on etckeeper machine from your computed, or use intermediate bare repo like that:
your pc --(push)--> remote repo
etckeeper machine <--(pull)-- remote repo
With keepconf tool you can get the files from remote servers and track them locally into a git repo.

Resources