🐙
Git Developer Guide
About
  • Overview
  • Scope of this book
  • Table of Content
  • 🐢Introduction to Version Control
    • What is Version Control?
    • Overview of git and it's benefits
    • Setting up Git on Different Platforms
  • 🍼Git Fundamentals
    • Initialising a new Git repository
    • Understanding the Git Workflow
    • Committing Changes and Writing Good Commit Messages
    • Viewing and Navigating Commit History
    • Git Basics - Practice Scenarios
      • Initialising a Git Repository
      • Committing Changes
      • Exploring Commit History
      • Amending and Undoing Commits
  • 🦕Working With Git
    • What is Git Branch?
    • Creating and Switching Between Branches
    • Merging Branches and Resolving Conflicts
    • Best Practices for Branch Management
    • Git Workflows
    • Git Log
    • Git Stash
    • Working with Git - Practice Scenarios
      • Creating and Switching Between Branches
      • Merging Branches and Resolving Conflicts
      • Branching Strategies in a Team Project
      • Rolling Back to a Previous Version
      • Experimenting with Feature Branches
      • Working with Stash
  • 🤝Working with Remote Repositories
    • Cloning a Repository from Remote
    • Pushing and Pulling Changes to and from Remote Repositories
    • Collaborative Workflows - Forking, Branching, and Pull Requests
    • Resolving Conflicts in a Collaborative Environment
    • Collaborating with Git - Practice Scenarios
      • Cloning a Remote Repository
      • Pushing and Pulling Changes
      • Collaborative Workflow with Forking and Pull Requests
      • Resolving Conflicts in a Pull Request
  • 🏆Advanced Git Features
    • Aliases and Custom Configurations
    • Working with Tags and Releases
    • Rewriting Commit History with Interactive Rebase
    • Utilising Git Hooks for Automation
    • Advanced Git Features - Practice Scenarios
      • Creating Custom Git Aliases
      • Working with Tags and Releases
      • Rewriting Commit History with Interactive Rebase
      • Using Git Hooks for Automated Testing
  • 😎Git in Real-World
    • Managing a Project with Multiple Contributors
    • Integrating Git with Continuous Integration, Continuous Deployment (CI, CD)
    • Versioning Assets with Git LFS (Large File Storage)
    • Deploying a Web Application using Git
    • Git In Real World - Practice Scenarios
      • Managing a Project with Multiple Contributors
      • Integrating Git with CICD Pipelines
      • Versioning Assets with Git LFS
      • Deploying a Web Application using Git
  • Git Troubleshooting
    • Common Mistakes and Pitfalls When Using Git
    • Undoing Changes with Git - Reverting and Resetting
    • Recovering Lost Commits or Branches
    • Dealing with Repository Corruption or Other Issues
  • Git Best Practices and Tips
    • Creating efficient git workflows: writing clean code for faster reviews
    • The importance of clean code in collaborative development
    • Significance of consistent naming conventions & coding Standards
    • Good code documentation for better git workflows
    • Writing meaningful git commit messages
    • Atomic commits in git & it's benefits for software teams
    • Structuring code & managing dependencies for better git workflows
    • Git branching strategies for software teams
  • Conclusion & Next Steps
    • Recap of Key Concepts and Commands
    • Further Resources for Expanding Git Knowledge
    • Encouragement and Tips for Continued Learning and Practice
  • License Considerations
Powered by GitBook
On this page
  • Initialising a new Git repository for a project
  • Configuring initial settings and global Git configurations

Was this helpful?

  1. Git Fundamentals

Initialising a new Git repository

PreviousSetting up Git on Different PlatformsNextUnderstanding the Git Workflow

Last updated 1 year ago

Was this helpful?

Initialising a new Git repository is the first step to start version controlling your project. In this section, we will walk through the process of creating a new Git repository for a project, understanding the repository structure, and configuring initial settings.

Initialising a new Git repository for a project

To initialise a new Git repository, navigate to the root directory of your project using the command line or terminal. Once you are in the project's root directory, use the git init command to create a new repository. Here's an example:

cd /path/to/project
git init

This command creates a new .git directory in the root of your project, which will contain all the necessary files and folders for version control.

Understanding the repository structure and the .git directory

The .git directory is the heart of a Git repository. It stores all the information about your project's history and tracks changes over time. Let's explore the contents of the .git directory:

  • config: This file contains the configuration settings specific to the repository.

  • description: This file contains a description of the repository (usually empty by default).

  • hooks/: This directory contains scripts that can be triggered at certain points in Git's workflow.

  • info/: This directory contains additional information and templates for certain Git commands.

  • objects/: This directory stores the data representing various versions of files and commits.

  • refs/: This directory stores references to commits (branches, tags, etc.).

It's important to note that the .git directory should not be modified manually unless you have a deep understanding of Git's internals.


Configuring initial settings and global Git configurations

After initialising the Git repository, it's a good practice to configure some initial settings. Git provides both repository-specific and global configurations. Let's start with the global configuration:

Set your name and email address globally, which will be used for identifying your commits:

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

You can also configure other settings globally, such as default branch names and editor preferences. Explore the available options by running:

git config --global --edit

To configure repository-specific settings, you can use the git config command without the --global flag within the repository directory. For example, to set a specific branch as the default branch for the repository, use:

git config init.defaultBranch main

These initial settings can be adjusted at any time using the git config command.

With the steps above, you have successfully initialized a new Git repository, understood its structure, and configured initial settings. Now you can start tracking changes, committing your work, and collaborating with others using Git's powerful version control capabilities.

For further reference and more advanced topics, you can explore the official Git documentation: .

🍼
Git Documentation