How can I use Git locally?

51,890

Solution 1

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.

Solution 2

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.

Solution 3

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

Solution 4

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.

Solution 5

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.

Share:
51,890
theonlygusti
Author by

theonlygusti

Updated on January 11, 2021

Comments

  • theonlygusti
    theonlygusti over 3 years

    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.