I'm testing and developing in an OpenShift All-in-One cluster in a VM. I needed my local working branch of a git repository cloned in my VM. I compiled bits and pieces of my web search into this post, so hopefully when the next developer searches the title of this blog they'll find this!

Substitute in the commands below:
  REPO=repoToClone
WORKING_BRANCH=workingBranchName
BARE_REPO="$REPO-bare"
PATH_TO_REPOS=/path/to/your/repo
REPO_PATH=/path/to/your/repo/$REPO
BARE_REPO_PATH=/path/to/your/repo/$BARE_REPO
PUBLIC_DNS_OF_VM
VM_USER=output of 'echo ${USER}' from VM
Run these commands while ssh'd into the VM.  I recommend putting these in a script so you can easily sync your local repositories to your VM whenever necessary:
sudo mkdir -p $PATH_TO_REPOS
sudo chown -R $USER:$USER $PATH_TO_REPOS
cd $PATH_TO_REPOS
git init --bare $BARE_REPO
git clone $BARE_REPO_PATH $REPO_PATH
cd $REPO
touch file.txt && git add . && git commit -m 'added a file so I could create a working branch'
git push origin master

Here is output of the above commands:

first_8_cmds
 
In local machine, clone your git repository to the VM $BARE_REPO:
  cd $REPO_PATH
git push -q ssh://$VM_USER@$PUBLIC_DNS_OF_VM$BARE_REPO_PATH --force --verbose

Here is output from the git push:

git_push_output
SSH back into VM and run these:
  cd $REPO_PATH
git pull (this will open a git vim window, enter 'wq' to continue merge)
git checkout $WORKING_BRANCH

Finally, here is a screenshot of the repository contents and branch name in the VM:

git_pull_ls_output
 
You now have your current local working branch of a git repository cloned to your VM :)

Über den Autor

UI_Icon-Red_Hat-Close-A-Black-RGB

Nach Thema durchsuchen

automation icon

Automatisierung

Das Neueste zum Thema IT-Automatisierung für Technologien, Teams und Umgebungen

AI icon

Künstliche Intelligenz

Erfahren Sie das Neueste von den Plattformen, die es Kunden ermöglichen, KI-Workloads beliebig auszuführen

open hybrid cloud icon

Open Hybrid Cloud

Erfahren Sie, wie wir eine flexiblere Zukunft mit Hybrid Clouds schaffen.

security icon

Sicherheit

Erfahren Sie, wie wir Risiken in verschiedenen Umgebungen und Technologien reduzieren

edge icon

Edge Computing

Erfahren Sie das Neueste von den Plattformen, die die Operations am Edge vereinfachen

Infrastructure icon

Infrastruktur

Erfahren Sie das Neueste von der weltweit führenden Linux-Plattform für Unternehmen

application development icon

Anwendungen

Entdecken Sie unsere Lösungen für komplexe Herausforderungen bei Anwendungen

Virtualization icon

Virtualisierung

Erfahren Sie das Neueste über die Virtualisierung von Workloads in Cloud- oder On-Premise-Umgebungen