Repository Management
git init→ Initialize a new Git repositorygit clone <repo-url>→ Clone an existing repositorygit remote add origin <url>→ Add a remote repositorygit remote -v→ List remote repositoriesgit remote remove <name>→ Remove a remote
git init
Syntax : git init [options] [<directory>]
# Initialize in current directory:
git init
# Initialize in a new directory:
git init my-project
# Set initial branch name explicitly:
git init -b main
# Create a bare repository:
git init --bare /srv/git/my-project.git
- Description: The
git initcommand is the foundation of Git usage. Whether you’re starting a new project, reinitializing an existing one, or setting up the bare repo for collaboration,git initis the first step in managing code with Git. - Usage: It creates the repository structure with
.git, sets up the initial branch (default ismainin modern Git), and prepares the repository to start tracking files and commits. - Think Tank: Git repositories can be initialized in different contexts:
| Type | Scope | Description |
|---|---|---|
| Local repo | Current directory | Standard repo with working tree |
| Bare repo | No working tree | Used for remote hosting or collaboration |
| Custom repo | With templates or separate .git dir |
Advanced setups for shared or specialized environments |
| Option | Description |
|---|---|
-q, --quiet |
Suppress output messages |
--bare |
Create a repository without a working tree |
-b , --initial-branch=
|
Set initial branch name |
- Best Practices:
- Always set the initial branch name (
-b main) for consistency - Use
--bareonly for server-side repositories - Initialize repos inside project directories, not system folders
- Add a
.gitignoreimmediately to avoid tracking unwanted files - Commit an initial README or setup file after initialization
- Always set the initial branch name (
Git - git-init Documentation

git clone
Syntax : git clone <repo-url> [directory]
# Clone a remote repository:
git clone https://github.com/user/project.git
# Clone into a specific directory:
git clone https://github.com/user/project.git my-project
# Clone with SSH:
git clone git@github.com:user/project.git
# Shallow clone (last 1 commit):
git clone --depth 1 https://github.com/user/project.git
# Bare clone:
git clone --bare https://github.com/user/project.git
# Mirror clone:
git clone --mirror https://github.com/user/project.git
- Description: The
git clonecommand creates a copy of an existing Git repository into a new directory. - Usage: It downloads the full history, sets up remotes (Default is
origin), and prepares a working directory. - Think Tank: Whether you’re cloning for development, backup, or CI/CD, understanding shallow, bare, and mirror options ensures you use the right strategy for your workflow. Git supports different cloning modes:
| Type | Description |
|---|---|
| Standard clone | Copies all history and files into a new directory |
| Bare clone | Creates a repo without a working tree (for servers/remotes) |
| Shallow clone | Copies only recent commits (reduces size and time) |
| Mirror clone | Exact replica including all refs, branches, and remotes |
| Option | Description |
|---|---|
--depth |
Create a shallow clone with only the last n commits |
--branch |
Clone only a specific branch |
--single-branch |
Limit clone to one branch instead of all |
--bare |
Create a bare repository (no working tree) |
--mirror |
Clone everything including refs and remotes |
--origin |
Set a custom name for the remote (default is origin) |
--recurse-submodules |
Initialize and clone submodules automatically |
--filter= |
Partial clone with object filtering (e.g., blobs only) |
--config key=value>
|
Set configuration during clone |
- Best Practices:
- Use shallow clones for CI/CD pipelines to save time and bandwidth
- Always verify remote URLs before cloning (especially with SSH)
- Use
--recurse-submodulesif the project depends on submodules - Prefer mirror clones for backups, not for everyday development
- Keep cloned repos updated with
git fetchorgit pull
Git - git-clone Documentation

git remote basics
- Remote repository: A version of your project hosted elsewhere (server, cloud, another machine).
git remote add origin https://github.com/user/project.git
Here, origin is the alias for the GitHub repo URL.
- Remote name: A short alias for the repository URL (commonly
origin). - Remote URL: The actual location (HTTPS, SSH, or local path).
git remote
Syntax : git remote [options] [subcommand] [name] [url]
# List remotes: → Shows remote names and URLs.
git remote
git remote -v
# Add a remote:
git remote add origin https://github.com/user/project.git
# Remove a remote:
git remote remove origin
# Rename a remote:
git remote rename origin upstream
# Change remote URL:
git remote set-url origin git@github.com:user/project.git
# Show remote details:
git remote show origin- Description: The
git remotecommand manages the list of remote repositories that your local Git repository can interact with. - Usage: It lets you add, remove, rename, and inspect remote connections, defines shortcuts (like
origin) for repository URLs, enables collaboration by linking your local repo to shared repos (e.g., GitHub, GitLab, Bitbucket). - Think Tank: Remote options to work with:
| Option | Description |
|---|---|
-v, --verbose |
Show remote names with URLs |
add |
Add a new remote |
remove |
Delete a remote |
rename |
Rename a remote |
set-url |
Change the URL of a remote |
show |
Display detailed info about a remote |
prune |
Remove stale remote-tracking branches |
- Best Practices:
- Always check remotes with
git remote -vbefore pushing - Use clear names (
originfor your fork,upstreamfor the main repo) - Prefer SSH URLs for secure authentication
- Regularly prune remotes to avoid clutter
- Document remote setup in project onboarding guides
- Always check remotes with
Git - git-remote Documentation


Updated on Dec 23, 2025