---
title: Mastering Git and SSH: A guide to becoming a code management pro - isla Studio
url: https://isla-stud.io/en/howtos-anleitungen/meistern-sie-git-und-ssh-ein-leitfaden-auf-dem-weg-zum-profi-im-code-management/
date: 2023-11-21
---

# Master Git and SSH: A guide to becoming a code management pro

Welcome to this guide where we will look at versioning and teamwork in software development. You will learn how to set up a private Git repository and synchronize it with an SSH target directory. This setup is ideal for developing WordPress plugins, themes or other code components where a detailed edit history and team collaboration are crucial.




			

						Master Git and SSH: A guide to becoming a code management pro - isla Studio
				
			
		
		

			Discover the world of Git and SSH! Learn how to create your own Git repository, synchronize with an SSH server and work effectively in a team.
		
			
			Course Provider:
			Person
		
			
			Course Provider Name:
			Saskia Teichmann
		
			
			Course Provider URL:
			https://www.saskialund.de/
		
			
			Course Mode:
			Online
		
			
			Course Workload:
			PT30M
		
	
	
	
	
	
			
			Course Type:
			Free
		
	
	
	


			
		







Table of contents
Toggle

Preparations for this guide



Before you start, make sure that your local setup meets the following requirements:




Git installed: Check whether Git is installed on your system and on the desired remote server. If not, you can download and install it from git-scm.com.



SSH access: Make sure you have SSH access to the server you want to work with.



Text editor: A basic text editor such as Nano, Vim or a similar program should be installed.



Internet connection: A stable internet connection is required to interact with remote repositories.




Setting up a private, local Git repository



First, set up your own private Git repository. This repository serves as a central point of contact where all versions of your code are stored.



git init MyProject # Initializes a new Git repository called 'MyProject'
cd MeinProjekt # Changes to the directory just created
git add .             # Adds all current files to the repository
git commit -m "First commit" # Creates a 'commit' with the message 'First commit'



Synchronize the Git repository with an SSH target directory



Here you synchronize your local Git repository with a remote directory via SSH. This allows you to securely store your work on a remote server and share it with team members.



ssh root@ihr-server.com "mkdir /path/to/target-directory" # Creates a directory on the server
ssh root@ihr-server.com "cd /path/to/target-directory; git init --bare" # Initializes a 'bare' Git repository on the server
git remote add origin ssh://root@ihr-server.com/pfad/zum/zielverzeichnis # Links your local repository with the remote repository. The remote repository is now managed under the identifier "origin". You can also use a different identifier.
git push origin master # Sends your local changes to the remote repository



Working with GitHub



If you prefer to work with GitHub or would like to connect an additional remote repository, you can also connect your local repository to a GitHub repository:



ssh root@ihr-server.com "mkdir /path/to/target-directory" # Creates a directory on the server
ssh root@ihr-server.com "cd /path/to/target-directory; git init --bare" # Initializes a 'bare' Git repository on the server
git remote add origin ssh://root@ihr-server.com/pfad/zum/zielverzeichnis # Links your local repository with the remote repository
git push origin master # Sends your local changes to the remote repository



Automatically push releases to the SSH target



Automate the deployment of your changes to the server with a post-receive hook:



ssh root@ihr-server.com # Connects to the server
cd /path/to/target-directory # Changes to the target directory
nano hooks/post-receive # Creates or edits the 'post-receive' hook script



Insert the following script to automatically apply changes to the working directory on the server:



#!/bin/sh
GIT_WORK_TREE=/path/to/working-directory git checkout -f # Updates the working directory on the server with the latest changes
chown -R username:groupname /path/to/workingdirectory # Changes the owner of the files in the working directory
chmod +x hooks/post-receive # Makes the script executable
Optional:
chown -R 33:33 /path/to/working-directory # Ensures that the files and directories in the working directory are assigned to a specific server user and server user group. I use 33:33 here because these are the IDs of my web server user and the web server user group www-data.



Pulling changes from the SSH target into the local repository



Transfer changes made on the SSH target server to your local repository:



ssh root@ihr-server.com # Connects to the server
cd /path/to/working-directory # Changes to the working directory on the server
git add .  # Adds all new or changed files to the commit
git commit -m "Description of changes" # Creates a new commit with your change description
git push origin master # Sends the changes to the remote repository
git pull origin master # Pulls the latest changes from the remote repository to your local repository



Pull changes from the GitHub remote repository to the local repository



Finally, you will learn how to efficiently integrate changes made in the GitHub remote repository into the local repository. This is particularly useful if you work in a team where several people are working on different parts of a project at the same time, such as when developing complex software or collaboratively creating a WordPress theme or plugin. By regularly updating your local repository, you ensure that you are always up to date with the latest collaborative work.



git fetch origin master # Fetches the latest information from the GitHub repository
git merge origin/master # Merges the changes from the GitHub repository into your local repository



Conclusion: Growing together through sharing and learning



We have now come to the end of this guide, and I hope you find these insights into using Git and SSH useful. Remember that mastering these tools will not only improve your individual software development skills, but also pave the way for more efficient and harmonious team projects.



I invite you to share your thoughts, experiences or questions in the comments. Have you already had experience with Git and SSH? Are there any particular challenges you've encountered or tips you'd like to share with the community? Your feedback is not only valuable to me, but also to other readers.



Your input could be the key that helps someone else solve a problem or discover a new perspective. I look forward to hearing from you!



Until next time, stay curious and get involved in the world of coding! 🌟👨‍💻👩‍💻