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
.
- Open terminal and go to the destination directory:
cd /users/zaatar/developer
- Create a new folder that will be your git working directory:
mkdir HelloWorld
- Go into this directory
cd HelloWorld
- Initialize your local git repository:
git init --bare
- Add the local remote to your repository so you can checkout and push from it:
git remote add origin /users/zaatar/developer/HelloWorld
- 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!