Offline use of Git

If you want to use git offline just install git, go to the root directory for your files and run git init to initialize the repository. You can then run git add file_path, git commit -m "First commit" etc.

The repository is stored under the .git directory that is created under the directory in which you run git init.


This article will give you offline scenarios to work with. Copying the .git folder is a simplistic approach and more tooling exists within git.

You can use the git bundle command to export and clone repos using a single file.

; first export
PC1 $ git bundle create repoName.bundle --all
; and clone
PC2 $ git clone /path/to/repoName.bundle

; after a few commits, export again
PC1 $ git bundle create repoName.bundle --all
; and pull
PC2 $ git pull /path/to/repoName.bundle

Yes, you can use Git offline. Git only requires an Internet connection when you use commands such as git remote, git pull, and git push with a remote repository that is stored on an Internet server. Any other commands that do not interact with a remote repository, such as git add, git commit, and git log to name a few, do not require any network connection. They modify files directly on your local machine in a subdirectory named .git. The size of this .git subdirectory is only limited by the physical capacity of the storage medium (typically a hard drive) where you save it.

To learn more about these commands, I suggest that you read Pro Git. This book is available for free online. The first three chapters teach you 99% of what you need for day-to-day use.

Note that Git is separate from GitHub. Since GitHub is a bunch of servers connected to the Internet, you need a Internet connection to use it. When you use GitHub you will use the commands that I listed earlier because your remote repository will be on a GitHub server.


By design, Git keeps the entire project history in each clone of the repository. Most of its operations do not need a network connection.

It needs a network connection only when you want to synchronize your clone with another clone located on a different computer. For example, when you want to make your changes available to your co-workers or get their contributions.

Read more about this item or, better, read the entire Git book to learn how it works.

As a side note, if you work alone on a project Git doesn't need a network connection at all. It is, however, recommended to keep a clone of your repository (and synchronize it often) on a different computer (on GitHub, for example) for backup reasons.

Tags:

Git