Privacy Policy
© 2025 linux101.dev

Git: Initialize a Repository

To start using Git in a project, you need to initialize a repository and optionally connect it to a remote server.

Initializing a Repo

Start a new Git repository

git init

Initializes a new Git repository in the current directory.

Setting a Remote

Add a remote repository

git remote add origin [url]

This command creates a named **alias** for a remote repository's URL. The name **'origin'** is a standard convention, but you can choose any name you like. Once this alias is set, you can use it as a shorthand for all future push, pull, and fetch operations.

List remotes

git remote -v

Lists all remote repositories and their URLs.

Setting the Upstream Branch

The upstream branch is the default remote branch your local branch is configured to track. Once set, you can use simple `git push` and `git pull` commands without specifying the remote or branch name.

Set upstream branch

git push --set-upstream origin [branch-name]

This command pushes your current local branch to the remote and sets it as the upstream branch. After this, `git push` and `git pull` will automatically know where to go.