🐙
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

Was this helpful?

  1. Git Fundamentals
  2. Git Basics - Practice Scenarios

Initialising a Git Repository

How to initialise a git repository

Scenario

Say you're working on a new project and you decide to setup version control in order to map out the history of the project, collaborate and better manage your development workflow over time. Here's a sample pattern to approach this usecase:

Step 1: Creating a New Directory

Before initialising a Git repository, you need to create a new directory to hold your project files. You can do this using the mkdir command in your terminal or command prompt:

mkdir my-project

Step 2: Navigating into the Project Directory

Navigate into the newly created directory using the cd command:

git init

After running this command, Git will create a hidden .git directory inside your project directory. This directory contains all the necessary metadata and objects to manage your repository.

Step 4: Verifying the Initialisation

To verify that the repository was successfully initialised, you can use the ls command with the -a flag to show hidden files:

ls -a

You should see the .git directory listed among the files and directories.

Step 5: Staging and Committing Files

Once the repository is initialised, you can start tracking changes to your project files. Let's assume you have some existing files in your project directory. To begin tracking them, you need to add them to the staging area using the git add command:

git add file1.txt file2.txt

This command stages file1.txt and file2.txt for the next commit. You can replace these filenames with the actual files in your project.

Step 6: Creating the Initial Commit

After adding the files to the staging area, you can create the initial commit using the git commit command. This command permanently saves the changes you have staged:

git commit -m "Initial commit"

The -m flag is used to provide a commit message describing the changes made in the commit. You can customise the commit message according to your project's needs.

Congratulations! You have successfully initialised a Git repository and created the initial commit for your project.

PreviousGit Basics - Practice ScenariosNextCommitting Changes

Last updated 1 year ago

Was this helpful?

🍼