My Profile Photo

Mohamed Zaatar Blog


A Readify developer/consultant. Passionate about Software development, IT and cars. This blog for my technical and personal views.


How to work with Git without remote server

Hello developers,

Did you encounter once that you want to work with local git repository only? Without hosting your code in any online service such as Github? I wanted to do it today and found it isn’t well-documented so I will guide you through my experience.

First locate the folder that will contain your working directory. In my current example, it will be /users/zaatar/developer.

  1. Open terminal and go to the destination directory: cd /users/zaatar/developer
  2. Create a new folder that will be your git working directory: mkdir HelloWorld
  3. Go into this directory cd HelloWorld
  4. Initialize your local git repository: git init --bare
  5. Add the local remote to your repository so you can checkout and push from it: git remote add origin /users/zaatar/developer/HelloWorld
  6. Create your own new master branch: git checkout -b master

That’s it! now you can now push and pull from it.

Now, you can work with your repository as it has a remote server. But it actually doesn’t have a remote one. The server of this repository is a local one hosted in the folder.

Tips:

  • Note, doing this command git init --bare without --bare option will create a repository with a remote server. So, you have to define it later
  • If you have already a repository and want to change the server from being remote to a local one? or if you want to change your current git local server, use: git remote set-url origin NEW_FOLDER
  • If you want to know where is the server folder is located: git remote -v

Hope that could help you!