Setting Up a Git Project from Scratch

Creating a New Git Repository and Pushing to Remote

Begin by turning a local directory into a version-controlled project.

cd your-project
git init

Stage all files for the initial snapshot.

git add -A

Record the staged changes with a descriptive message.

git commit -m "Initial project commit"

Link the local repository to a remote counterpart on a hosting service like GitHub or GitLab.

git remote add origin https://example.com/user/repo.git

Establish a working branch instead of pushing directly to main or master.

git branch feature-setup

Switch to the newly created branch.

git checkout feature-setup

Upload the branch to the remote. During early setup, force-pushing may be necessary to align the remote branch history with your local one.

git push -u origin feature-setup --force

Useful Shortcuts

A single command can both create and jump to a branch.

git checkout -b feature-setup
# To remove the branch afterward:
# git branch -d feature-setup

View all available branches, including remote tracking ones.

git branch -a

Fetch the latest branch metadata from the remote without merging.

git remote update

Starting from an Existing Remote Branch

If the remote repository already contains a branch designated for you, clone it directly and set up tracking.

git clone https://example.com/user/repo.git
cd repo
git checkout -b feature-setup origin/feature-setup

Personalizing Your Git Identity

Define the name and email that will appear in your commits.

git config --global user.name "your-name"
git config --global user.email "you@example.com"

Commit Message Style Guide

Consistent prefixes help clarify the nature of each change.

  • feat – a new feature or page (feat: add password reset flow)
  • fix – a bug resolution (fix: correct authentication timeout)
  • modify – alterations to existing functionality (modify: enhance search filters)
  • delete – removal of code or files (delete: remove deprecated API routes)
  • perf – performance enhancement (perf: optimize database queries)
  • refactor – code restructuring without changing behavior (refactor: split monolithic service into modules)
  • style – formatting or cosmetic adjustments (style: enforce consistent indentation)
  • docs – documentation or comment changes (docs: update installation instructions)
  • build – tooling or dependency updates (build: upgrade bundler to v3)
  • chore – mainetnance tasks outside source or test directories (chore: add .editorconfig)
  • ci – continuous integration adjustments (ci: migrate to containerized CI)
  • test – test-related additions or modifications (test: add integration tests for API endpoint)
  • workflow – development process improvements (workflow: introduce branch protection rules)
  • revert – reversal of a prior commit (revert: undo changes to billing module)
  • types – type definition updates (types: refine user model interfaces)
  • wip – work-in-progress, not intended as final (wip: initial draft of payment gateway integration)

Tags: Git version-control repository commit-conventions

Posted on Mon, 02 Nov 2026 16:46:59 +0000 by ramram