A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/git-guides/git-init below:

Git Guides - git init · GitHub

git init turns any directory into a Git repository.

git init is one way to start a new project with Git. To start a repository, use either git init or git clone – not both.

To initialize a repository, Git creates a hidden directory called .git. That directory stores all of the objects and refs that Git uses and creates as a part of your project's history. This hidden .git directory is what separates a regular directory from a Git repository.

Common usages and options for git init

You can see all of the options with git init in git-scm's documentation.

Starting a new project can be confusing. Sometimes, it's unclear if you should use git init, git clone, or both.

git init: One Person Starting a New Repository Locally

Your project may already exist locally, but it doesn't have Git yet. git init is probably the right choice for you. This is only run once, even if other collaborators share the project.

git clone: The Remote Already Exists

If the repository already exists on a remote, you would choose to git clone and not git init.

If you create a remote repository first with the intent of moving your project to it later, you may have a few other steps to follow. If there are no commits in the remote repository, you can follow the steps above for git init. If there are commits and files in the remote repository but you would still like it to contain your project files, git clone that repository. Then, move the project's files into that cloned repository. git add, git commit, and git push to create a history that makes sense for the beginning of your project. Then, your team can interact with the repository without git init again.

The default behavior of git init is to transform the current directory into a Git repository. For an existing project to become a Git repository, navigate into the targeted root directory. Then, run git init.

Or, you can create a new repository in a directory in your current path. Use git init <directory> and specify which directory to turn into a Git repository.

git init in the wrong directory

Running git init in the wrong place will create unintended repositories. You may have noticed strange error messages when using Git. Maybe you suspect that another parent directory is also a Git repository.

To fix this, you first need to track down which directory is the unintended repository. Use git status to see if the current directory is tracked by Git. If it is, you can either run ls -al and look for an otherwise hidden .git directory.

If you don't see it, navigate one level up in the directory structure with cd ... Use git status again in combination with ls -al. Repeat this until you find the .git directory.

Once you find the .git directory, and you are sure that you don't want that to be a Git repository, use rm -rf .git. This will remove the .git directory, effectively un-initializing that repository. Run git status again to confirm that Git is no longer tracking any of these files. (It could be possible that multiple layers of .git directories are present.)

Return to your working repository, the one that you expect to be under version control. Things should be working as expected.

Contribute to this article on GitHub.

Get started with git and GitHub

Review code, manage projects, and build software alongside 40 million developers.

Sign up for GitHub Sign in

You can’t perform that action at this time.


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4