81

I'm working on a project at the moment, which I'd like to eventually make public on github, but, for the moment, needs to remain private.

Github needs users to pay in order to host a private repository, which I'm unwilling to do, so just creating a private github repository is not an option for me.

However, I would still like to use git for version tracking etc. whilst I'm working on the project locally, so that when I do eventually put the project on github, all of this information, the project's changes start-to-finish, will be available.

But, I have no clue how to use git without a remote server. I'm wondering now if it just exactly the same, simply without the need for git push.

The perfect answer for me would be a step-by-step walkthrough, telling me exactly what I should type into the terminal to set up and maintain a local git repository.

2
  • 5
    ....it's the same, except you don't git push. Sep 4, 2015 at 21:22
  • 1
    An up vote for a good and same question.
    – Franky
    Jul 2, 2019 at 6:28

6 Answers 6

47

You only need to push if you want to use a remote server.

When working locally, you still need to git init to set up the repository, but after that you only need to do the steps

git add
git commit -m "new commit"

to save ("commit") your changes.

Don't git push at all, and don't git pull — there's no remote to sync changes with (git push and git pull just push and pull changes from the remote/online repository).

Type:

git log

To see that your changes have been recorded.

1
  • Is there any documentation for someone who is complete new to git, to install and use git on a local network ? I mean run git on a local windows server, and connect from desktop computers to that git ?
    – GuidoG
    May 8, 2021 at 6:28
32

A remote server is never required. You can just do git init in your project. If you decide to add a remote server later, it will maintain all the history when you push it.

Also if you want you can use Bitbucket or GitLab. Both of them allow private repositories for free.

3
  • 1
    What about committing? Viewing changes with git log? Sep 4, 2015 at 21:29
  • You would use git commit just like you normally would. The only difference is you won't do git push.
    – jfadich
    Sep 4, 2015 at 21:30
  • 1
    As DVCS, all the operations (except sharing an retrieving commits with fetch, pull an push) with git are 100% local. No need if a server... Just git init like said earlier and your done ;-) And feel free to use bitbucket or gitlab before switching to github if needed!
    – Philippe
    Sep 5, 2015 at 8:23
16

Actually you just have to run

git init

on your local folder. This will already create you a repository within the existing folder as a minimal setup.

If you would like to have a setup more similar to a distributed setup with a repository at some other place/server, use

git init --bare your_project.git

to create a repository (similar to the server side repository), and

git clone <path_to_repository>

in the local folder where you would like to work

1
  • 1
    It's really great, it also works with ssh if you have your git outside of your device. Just use the format user@server:/abs/path/to/your/repo.git. Nov 1, 2021 at 20:25
7

Just make a local git project and dont push it. You can do it later. Or you make a empty github project and pull the empty project. Now you can work locally and if you are ready you can push it to github.

No worry, just try.

2

Git allows you to create a local repository on your machine. Only when you're actually ready to publish it to a remote is when it becomes available to the public.

Otherwise, it's no different than working with Git without an internet connection; you can still commit, tag, rebase, create branches, and all of that wonderful stuff, but you can't push or pull.

In the project directory, initialize it just like you would any other Git project.

git init

Work on it like you would any other Git project with commits. Since you don't have a remote server to push it to, any attempts to push or pull would fail anyhow.

When you're ready to create your remote server, GitHub will do a very good job of walking you through what you have to do in order to get that bootstrapped.

1

I'm dealing with the same thing. Unless that I cannot really have a private project on Github, because of unfair sanctions to some country. I don't want to repeat the other answers, because they were straight forward, and I'm doing just the same. To add a bit information, if you don't like terminal environment and you don't want to go through every change and record them by your terminal, simply install Atom editor, install the Github plugin, in newer versions the plugin installed from the beginning and you really don't need to worry about it. When you created a folder you can initialize the git by either the Git icon or simply typing in the terminal at the exact directory :

git init

Then, when you add changes to your code or whatever, the git tracks it and you can commit your changes through the Atom editor. enter image description here The only problem might be that you cannot use all of the commands that are available via terminal, but it's enough to actually work. But you can fill the gaps by using the terminal when you really need other git commands. This plugin is available on other IDEs as well. And works just fine.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.