Skip to main content

Command Palette

Search for a command to run...

Git (Version Control system)

Published
•4 min read•View as Markdown
N

DevOps Engineer with a Diploma in Computer Science and Engineering and a Cloud and DevOps Master's certification from Intellipaat. I bring over 2.6 years of industry experience, including a role as a Associate Devops engineer at Optum Global Solutions (UHG) and over a year as a Sr. DevOps Engineer at iEnergizer. Passionate about Cloud and DevOps, I specialize in cloud platforms like AWS, Azure, and GCP, with hands-on experience in automation tools and building CI/CD pipelines. I’m adept at ensuring seamless software delivery through efficient infrastructure management and automation. Eager to contribute my skills to ambitious projects and drive success in the DevOps space. • Proficient in providing continuous support for the creation of Jenkins Pipelines and deploying containers, ensuring seamless integration and delivery processes. • Specialized in Linux, Shell scripting, Cloud Technologies, and CI/CD technologies, with a track record of implementing robust and scalable solutions. • Demonstrated expertise in optimizing development workflows, enhancing system reliability, and fostering collaboration between development and operations teams. • Proven ability to adapt to evolving technologies and industry best practices. • Committed to delivering high-quality solutions that align with organizational goals and drive efficiency in software development and deployment processes.

1. Module : Version Control with Git (from the first PDF)

What is Version Control?

  • Version Control: A system to track changes in documents, programs, etc., over time. It enables collaboration on projects, managing versions of files efficiently, and keeping track of changes made by different people.

Problems Before Version Control

  • Manual Versioning: Before version control systems (VCS), changes were handled manually, leading to complications when integrating changes from multiple developers.

  • Time-Consuming Collaboration: Merging changes from different developers often required manual effort.

  • No Easy Access to Previous Versions: It was difficult to retrieve previous versions of the software.

Advantages of Version Control

  • Automatic Versioning: Tracks changes automatically.

  • Simplified Collaboration: Multiple developers can work on the same project simultaneously.

  • Efficient Storage: Only modified parts are stored, reducing storage requirements.

Types of Version Control System (VCS)

  • Centralized VCS (CVCS): A single repository on a central server where developers push their changes.

  • Distributed VCS (DVCS): Developers clone a copy of the repository locally and do not need an internet connection for every operation.

Introduction to Git

  • Git: A Distributed VCS used for tracking changes in files. Git allows developers to clone the entire project and work offline. Changes can later be pushed to a central repository like GitHub.

Git Lifecycle

  • Working Directory: Where the files are located on your local machine.

  • Staging Area: Files are moved to this area when they are ready to be committed.

  • Commit: The act of saving a snapshot of the staged files into the Git repository.

Common Git Commands

  • git init: Initializes a Git repository.

  • git status: Checks the status of files.

  • git add: Adds files to the staging area.

  • git commit: Saves the staged changes with a commit message.

  • git remote: Links your local repository to a remote one (like GitHub).

  • git push: Pushes your committed changes to the remote repository.

  • git clone: Copies a repository from a remote server to your local machine.

  • git pull: Retrieves the latest changes from a remote repository.

  • git branch: Manages different branches for parallel development.

Merging Branches

  • Git Merge: Combines the changes from different branches into one.

  • Git Rebase: Another way to integrate changes but without creating a merge commit, leading to a cleaner history.

Collaboration in GitHub

  • Adding Collaborators: Developers can be added to a repository to work together.

  • Pull Requests: A way to propose changes in a repository and merge them after approval.


2. Hands-On – Common Git Commands (from the second PDF)

This document outlines some of the hands-on commands in Git:

1. git init

  • Initializes a new Git repository.

2. git status

  • Shows the current status of the repository, listing files that are tracked or untracked by Git.

3. git add

  • Adds files to the staging area (use git add . to add all files).

4. git commit

  • Records the changes from the staging area in the local repository with a descriptive commit message.

5. git remote

  • Adds a reference to a remote repository (usually GitHub or similar).

6. git push

  • Pushes the committed changes from your local repository to the remote repository.

7. git clone

  • Clones an existing repository from a remote source to your local system.

8. git pull

  • Fetches the latest changes from the remote repository and merges them into your local repository.

9. git branch

  • Creates or deletes branches, which allow developers to work on different features or fixes simultaneously without affecting the main project.

10. git checkout

  • Switches between different branches.

11. git log

  • Shows the commit history for a repository.

12. git stash

  • Temporarily saves changes that are not yet committed, allowing you to switch branches or perform other tasks without losing your current work.

13. git revert

  • Undoes a specific commit by creating a new commit that undoes the changes made in the target commit.

Hands-On: Git Rebase

  1. git rebase

    • Git Rebase is used to integrate changes from one branch into another by rewriting the commit history. This avoids the creation of merge commits and leads to a cleaner project history.

    • The process typically involves checking out the local branch on which the rebase is performed. This brings your branch up to date with changes from another branch, while maintaining a linear history.

  2. git log

    • You can view the commit history of the repository using the git log command. This shows all the commits in chronological order, allowing you to inspect the current state of the project history.

The document likely contains practical steps on how to use git rebase in a real-world project, making it useful for maintaining a cleaner project history when collaborating with teams.