Understanding git init

Your three four understandings are more or less correct, though you're missing a few details.

git init initialises (i.e. creates) a repository. Each project should be in its own repository.

If you downloaded your project using git clone then you don't need to run git init again.

You should be able to copy your project to another directory without any adverse effects. That path was probably chosen by default. Be sure to move the whole directory. The metadata that git needs to run is stored in hidden files in the project's directory.

Pushing and pulling can get complicated, especially when you're working on a project with others, and when you're using branches. It's not really sensible for me to write out a complete intro to the topic here, so I'd suggest you go read Pro Git for a more thorough explanation.


That's actually a lot of questions and misunderstandings. I'm not sure I'd be able to address them all so I'm only going to address what's directly asked.

  1. git init is for every project

    Almost correct. git init is used to start using git on a project that's not under git. For projects that are already under git you use git clone.

  2. The git folder under "Users" is local repo

    Almost correct. The folder is actually .git not git. This comes from the unix convention that all files and folders that start with a dot are considered hidden.

    Secondly, the folder is not under your Users folder. It is under your project folder. So the folder C:/Users/myUser/ is one project. If this is not your intention then you most likely have accidentally executed git init in your User folder.

    Each project has one .git folder in the project's root directory and that is the project's repository. This is one of the reasons git is so fast compared to svn or cvs - the entire repository is processed on the local hard disk without any network traffic.

  3. When I do git push , it takes from that local repo, and puts to remote

    Correct, but only for repos that have remotes (which are usually repos that you create by using git clone to copy a remote repo).

    Note that the remote repo does not need to be on another machine. You can git clone a project from a local folder into another folder and then you can push changes from the new folder back to the original folder.

    The git clone command automatically sets up the necessary config for your repo to connect back to a remote. But you can also manually configure a repo set up with git init to connect to a remote.

  4. what "manages" it

    The .git folder manages your project's repo. Git doesn't run as a server*. Instead the .git folder acts as your local 'server' that all the git commands communicate with. Basically, running a git command edits the contents of the .git folder.

    *note: Remote repos do run servers so you can connect to them. But technically they're not really git servers. They're file servers that git can download from and upload to.


git init is only for when you create your own new repository from scratch. It turns a directory into an empty git repository.

When you use git clone to clone an existing repository into a new one, git init is neither necessary nor desired.

Tags:

Git