Git Quick Start
👋 Hi, I’m Huzefa Ahmed, and I’m starting my DevOps engineering journey! 🚀 I’m passionate about AWS DevOps and aim to land a full-time role in this field.
As I dive into cloud technologies, automation, and continuous integration, I’ll share my progress, insights, and challenges. Let’s connect, learn, and grow as a DevOps community!
Follow my journey on Hashnode and LinkedIn as I work towards securing a job in DevOps!
LinkedIn: https://www.linkedin.com/in/huzefa-ahmed-15720b278/
Getting Started with Git
In this guide, we'll walk through the steps to install Git, configure user information, create and initialize a Git repository, make your first commit, and use Git to track changes and view logs.
1. Installing Git On Linux:
Before you can use Git, you need to install it on your system.
Linux: On Debian-based distributions (like Ubuntu), you can install Git using:
$ sudo apt-get update
$ sudo apt-get install git
To verify the installation:
$ git --version
2. Configuring User Information
After installing Git, you need to configure your user information, such as your name and email address. This information is used to identify the author of the changes in the repository.
Run the following commands to configure Git globally (applies to all repositories):
$ git config --global user.name "Your Name"
$ git config --global user.email "your.email@example.com"
You can verify the configuration with:
$ git config --list
3. Creating a Git Repository
A Git repository is a directory that contains your project's files along with all the changes and history. You can either create a new repository or clone an existing one.
Creating a New Repository
Navigate to your project directory (or create a new directory):
$ mkdir my-project
$ cd my-project
Initialize the Git repository:
$ git init
This command creates a hidden
.gitdirectory that contains all the necessary metadata and history for the project.
4. Making Your First Commit
To commit changes, you first need to stage the changes and then commit them to the repository.
Create or modify a file in your project directory:
$ echo "Hello, Git!" > hello.txt
Stage the file using the
git addcommand:$ git add hello.txt
This adds the file to the staging area, preparing it for the next commit.
Commit the changes with a message describing what was changed:
$ git commit -m "Initial commit: Added hello.txt"
This command creates a new snapshot of the staged changes in the repository.
5. Git Tracking and Logs
Git provides powerful tools to track changes in your project and view the commit history.
Tracking Changes
View the status of your repository to see which files have changed, are staged, or are untracked:
$ git status
This command shows the current state of the working directory and staging area.
View changes made to a file:
$ git diff
This shows the differences between the working directory and the staging area.
Stage and commit changes:
Stage specific files:
$ git add filename.txt
Commit the changes with a message:
$ git commit -m "Updated filename.txt with new changes"
Viewing Commit Logs
Git logs provide a history of commits in the repository.
View the commit history:
$ git log
Filter out the log:
$ git log —author=”user_name”