how to create a virtual copy of git repo on a test server - linux

I am fairly new to Git. I have worked locally, but today i need to setup a remote machine with the git. I have no idea how.
Basically my setup is like this.
I have a windows machine which has a vmware player installed, which is used to connect to the dev ubuntu linux machine where out Git repo is situated. I putty to the dev machine and do all the operation related to git with username common to all the developers username : dev
Now there is a new rollup that is created in the dev git repo which is required to be deployed on our ubuntu linux test server. I have my account in test server. username:ash.
What are the steps that should be followed to setup this. I have some time back had a discussion with one of my colleague who had shared about using SSH key. As he is the only contact person who is not available, I have no info how to proceed. I have created the SSH key.

login to the machine as "ash".
ash#gitserver:~$
create a new directory that will contain the git-repository
ash#gitserver:~$ mkdir rollout.git
change into the directory
ash#gitserver:~$ cd rollout.git
initialize the git repository
ash#gitserver:~/rollout.git$ git init --bare
go back to your dev machine and clone the newly created repository or add it to the "remote"s of an existing git repo. use "ssh://ash#gitserver/~/rollout.git" as the remote-url.
[update for cloning]: make sure that there is not already a "rollout" directory in the directory where you want to clone to. for simplicity, create an empty directory "foo/" and try to clone into that directory. you can then move the cloned repository to wherever you want to.
push changes to the new repository.......done!
the use of ssh-keys will make authentication simpler and/or more secure but is in no ways necessary (or related) to setting up the git repository.

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.

Unable to connect to Linux git Repo from Windows machine

So recently I've been trying to set up a Git server to manage personal projects and work. I created a bare Git repo on a spare laptop running Ubuntu and I installed Git Bash on my Windows machine. Right now I'm having some issues in actually being able to clone my Ubuntu git server to my Windows computer.
I used git remote add origin myserver#myserver-Dell-System:/home/myserver/CentralRepo.git but
whenever I try to clone to my Windows machine, Git bash spits out this error:
ssh: Could not resolve hostname myserver#myserver-Dell-System: Name or service not known
fatal: Could not read from remote repository.
Please make sure you have the correct access rights and repository exists.
I double checked my add to make sure the address of my Git server was correct and I assume Git bash for Windows comes with OpenSSH.
Does anyone know why this is happenning and how I can get my Windows machine to sucessfully clone from a server to itself? Thanks!
A valid ssh url would be
auser#myserver-Dell-System
You can check if you can resolve and connect to that server with
ssh -T auser#myserver-Dell-System
That supposes that you have generated a public/private ssh key pair, and added your public key to ~auser/.ssh/authorized_keys file first.
See "Adding SSH Keys to authorized_keys"

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

Migrate repos between instances of Gitlab

Due to my old installation of Gitlab being too difficult to upgrade (Thread on TKL support forums: http://www.turnkeylinux.org/forum/support/20120913/upgrading-gitlab ), I have downloaded the current TKL Gitlab distro, and followed Gitlabs standard upgrade path so that I now have a fully upgraded Gitlab 6.1 installation running with TKLBAM and all that good stuff. So far so good.
But, it turns out that our old version of gitlab does not give HTTP urls to repos, so that means that I can't use the "Import existing repository" function in Gitlab 6.1
I know that i can simply copy the old Git repositories from the old VM to the new one, but how can I make these repositories visible in Gitlab on the new VM?
I recently migrated from gitolite to gitlab and the official rake task gitlab:import:repos worked for me. I am using gitlab 6.1.0 (82f3446). Here is what I did:
rsync bare repos from gitolite to repositories/{group}/. Make sure to replace {repository} with the name of the gitolite repo, and change the hostname of your gitlab server.
rsync -rth --progress repositories/{repository}.git \
git#gitlab-server:/home/git/repositories/{group}/
Here, {group} is the name of the user group you want the repository to be added to. If you don't have any specific group, choose root as the group name.
Fix permissions – only necessary when the rsync user is not git:
sudo chown -R git:git repositories/{group}/
cd ~/gitlab
Run the rake task to import all new repositories:
bundle exec rake gitlab:import:repos RAILS_ENV=production
Now if you login as Administrator you will find the new project added.
For more information, refer to the "Import bare repositories into GitLab project instance" under http://{your-gitlab-server}/help/raketasks.
In your case, you can login to your old TKL system and rsync all bare repos to the new instance, followed by an import.
One option would be to:
Clone the old repo from gitlab onto a dev machine.
Create a blank repo on the new gitlab.
Add the new repo as a remote on the dev machine.
Push everything back to the new repo.
Remove the old repo from remote repos list.
To create a remote called newRepo, do: git remote add newRepo gitlab.localhost.com:User/newRepo.git (replace the url on the end with the one for your repo)
I did it practically the following way after reading ChrisA answer, which gave me a little headache about how to do it practically. The example copies a repo from github to gitlab, to make source and destination a little bit clearer.
Clone the old repo from github onto a dev machine (which creates a bare repo):
$ git clone --mirror git#github.com:me/myrepo.git
Create a blank repo on the new gitlab.
Add the new repo as a remote on the dev machine.
$ cd myrepo.git
$ git remote add newRepo git#gitlab.com:me/myrepo.git
Push everything back to the new repo.
$ git push --mirror newRepo
That's it.
This way it copied all branches and tags to the new destination.
You can now remove the cloned bare repo from your dev machine.
If your Gitlab is >= 8.9, then you can use export/import to migrate repos.
Since GitLab 13.8 (January 2021), you now have:
Migrate Groups directly between instances
A faster and easier way to migrate your GitLab Groups is on the way.
Group Migration is a new feature that lets you copy a GitLab Group from one instance to another directly, without having to export and import any files.
In this release, we migrate only the Group object with basic fields.
We plan to follow up with more and more fields and related objects until all relevant data in a Group is migrated in this easy-to-use fashion.
See Documentation and Epic.

view the git repository on remote linux server -> in Windows?

Problem: Need to view Git history visually in windows, repository is on remote Linux server (Ubuntu).
Question: What are two easy ways to view the git repository on remote linux server -> in Windows?
I have initially tried mirroring the remote mirror, then viewing it locally - updating when needed, but I get an error when connecting,
git clone --mirror username#serveraddress.com:/home/username/projectfolder
fatal: Could not read from remote repository.
Please make sure you have the correct access rights and the repository exists.
Again I'm on Windows using Git Bash, trying to clone a remote repo that's on Linux.
Thanks in advance.
There is no importance where the repo resides.
As the error said,
1- make sure you have the address right
2- make sure you have access to the address

Resources