~/
hackweb.dev
Creating a Repository
Quiz
⌘K
...
~/
/tutorials
/git/git-init/edit
~ Contribute
Suggest a correction or improvement. The author reviews it before it goes live.
Loading...
Comment
0 / 300
Typo
Grammar
Broken link
Clarify
Code
en/tutorials/git/3git-init
Write
Preview
Diff
# Creating a Repository To start tracking a project with Git, you need to create a repository. This is a one-time setup per project. ## Initializing a Repository Navigate to your project folder and run: ```bash git init # Initialized empty Git repository in /path/to/project/.git/ ``` ## What Happens Inside .git/ Git creates a `.git/` directory with everything it needs: ```bash ls -la .git/ # HEAD # config # description # hooks/ # info/ # objects/ # refs/ ``` This folder contains your entire history once you start committing. ## Working Directory vs Repository - **Working directory**: Your project files (the ones you see and edit) - **Repository**: The `.git/` folder where Git stores all tracking data ## Alternative: git clone Instead of starting fresh, you can copy an existing repository: ```bash git clone https://github.com/user/project.git ``` This creates a full copy with all history and files. ## Best Practices - Initialize Git at the start of a project - Keep your `.git/` folder safe (don't delete it) - Use `git clone` for existing projects - Add a `.gitignore` file early to exclude files ## Common Mistakes - Running `git init` multiple times in the same project - Deleting the `.git/` folder (destroys all history) - Forgetting to initialize before making commits - Not adding a `.gitignore` for sensitive files
No changes yet
Reset to original
Submit suggestion
cancel