Skip to content
Tech Talk Tavern/
Menu

post · January 15, 2024 · 3 min read

Introduction to Git

By Saleh Elnagar

Git
Share:LinkedInX
Git Workflows illustration for Introduction to Git

Git is a distributed version control system that allows developers to track changes in source code while collaborating with others. It records every change made to a project, enabling you to explore previous versions and revert when necessary.

Getting started with Git involves a few basic commands:

  • git init initializes a new Git repository in your project directory.
  • git clone copies an existing repository from a remote server to your local machine.
  • git add stages changes to be committed.
  • git commit -m "message" records the staged changes with a descriptive message.
  • git push sends your committed changes to a remote repository like GitHub.
  • git pull fetches and merges changes from the remote repository into your local branch.

These commands form the foundation for using Git effectively. As you become more comfortable, you can explore advanced features like branching, merging, and tagging to support collaborative workflows and release management

Configuring Git and Getting Started

Before you start committing code, configure Git with your name and email address so each commit is properly attributed. Use the following commands:

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

Your name and email are stored in Git’s configuration and will apply to every repository on your system. After configuring your identity, you can initialize a new project with git init, which creates a repository in the current directory. If you’re starting from an existing codebase, use git clone <url> to copy the remote repository to your machine.

Staging and Committing Changes

Git uses a two-step workflow. First you stage changes with git add, which stores snapshots of your files in the index. Staging lets you decide exactly which changes to include in your next commit. When you’re ready, run git commit to record the staged changes in the repository history. Use git commit -a to automatically stage all modified tracked files, but note that new files still need to be added manually.

Inspecting Your Project

Once you have a few commits, you’ll want to inspect what’s changed. The git status command shows which files are new, modified or staged, while git diff displays the actual changes in your working directory. To review the differences you’ve staged for your next commit, run git diff --cached. These commands help you understand exactly what will be recorded when you commit.

Branching and Merging

Branches let you develop features or fixes in isolation from your main line. Create a branch with git branch feature-xyz and switch to it with git switch feature-xyz (or git checkout). Once work is complete, merge it back into the main branch with git merge feature-xyz. If both branches modify the same lines, Git will flag a conflict and ask you to resolve it. After merging, you can delete the feature branch with git branch -d feature-xyz.

Best Practices and Tips

Write commit messages that start with a concise summary (50 characters or less) followed by a blank line and a more detailed explanation. Keep commits focused on a single change, use descriptive branch names, and push your branches frequently to share work with your team. Regularly pull and merge changes from the main branch to minimize conflicts.

Quick AI Summary

Git is a distributed version control system that allows developers to track changes in source code while collaborating with others. It records every change made to a project, enabling you to explore previous versions and revert when necessary.

Original article body above remains unchanged.

Continue Reading

Related Posts

Git Workflows illustration for Configure Git to Sign All Your Commits with GPG (Step‑by‑Step)
November 16, 20254 min read

Configure Git to Sign All Your Commits with GPG (Step‑by‑Step) Signing your commits proves they came from you and haven’t been altered. Many teams now require signed commits to protect their supply chain. In this guide you’ll generate a GPG key, configure Git to sign every commit and tag, upload your public key to GitHub/GitLab/Bitbucket […]

Git Workflows illustration for Configure Git to Sign All Your Commits with GPG (Step-by-Step)
April 17, 20254 min read

Signing your commits proves they came from you and haven’t been altered. Many organizations require signed commits to protect their supply chain. This step-by-step guide walks you through generating a GPG signing key, configuring Git to sign every commit and tag, uploading your public key to popular Git hosting services (GitHub, GitLab, Bitbucket), and troubleshooting […]

Azure Architecture illustration for Azure Terraform Conventions: How to Design & Enforce a Real-World Naming Strategy
June 7, 202512 min read

Repository: https://github.com/SalehElnagar/azure-terraform-conventions This article walks through how to think about Azure naming conventions and how to turn those decisions into code using the azure-terraform-conventions GitHub repository. That repo contains: The goal is not “just use whatever the repo does”. The goal is: capture your organization’s naming decisions once, codify them with this library, and then […]

#Azure#DevSecOps#IaC

Get New Playbooks Weekly

Join the newsletter for practical Azure, Terraform, and DevSecOps guides. One actionable email per week.

Comments

Enable comments by setting NEXT_PUBLIC_GISCUS_* environment variables.