Probably a simple question but when you are using git locally on your computer do you lose branches and commits when the computer is turned off?
Probably a simple question but when you are using git locally on your computer do you lose branches and commits when the computer is turned off?
No. When a repo is initialized with git, all local changes and branches are saved in the git working directory. This is somewhat same as saving a file in your computer. Hence, local changes will not but losed.
A commit is just a snapshot of the contents of the repository. When you give commit, git computes a hash value over the contents of the repository and saves the state of the repository. Here is a good reference on recording changes to git repository.
No, they won't be lost. Everything is persisted to your file system. As long as you do not format your FS or throw it away, your local repository will still be there after a reboot.
Commits, directories, and file contents are stored under the .git/objects/ directory and branches are stored under .git/refs/ or in .git/packed-refs.
If you are asking however if the local history will be unavailable to others who might have configured your repo as a remote, then yes, they will not be able to access the remote history while your computer is turned off. When you turn it back on, they can fetch from or push to it again.
No,branches and commits will not lost when you switched off.
Git generally used as version control system. It tracks the changes you make to local files, so you have a record of what has been done, and you can revert to specific versions should you ever need to.
Git also makes collaboration easier, allowing changes by multiple people to all be merged into one source.
The beauty (and sometimes curse) of git is that every user typically has an entire archive, or repository, on their machine, including all past revisions. There is no principal distinction between a remote repository and the one on your local machine: Both are parallel futures coming off of a common archive state in the past.
Git operations generally work on that local repository, unless you pull or push to remote ones. Your operations are persistent, the history is recorded, and the entire toolbox of git is at your disposal even without any internet connection. Yes, all changes are on disk and survive power cycles, as long as your disk does. It is a perfectly valid use case to have a local, self-contained repository that never communicates with anything; it simply serves as a means to organize and save your work. For backup purposes you may want to clone it on a different machine, but you could as well simply zip it somewhere.
But git shines when it comes to collaboration, when clones of repositories are used to work in parallel. At some point you may want to re-join the parallel work on those repositories but that is a different story — and is no different from reconciling two repositories on your own computer.
No, unless the "switch off" is a hard shutdown, while processes are running, in which case files might possibly be corrupted, and the integrity of your Git repository compromised.
Beside that, it is always a good idea to push (even a work in progress) to a remote repository in order to have a better guarantee nothing would be lost even in the case of a catastrophic event on your local computer.