Blogs


Basic Git for DevOps

Explore the fundamental Git commands essential for effective version control in software development and DevOps workflows. From cloning repositories and initializing new projects to branching, merging, and configuring user information, this guide provides concise examples and explanations to empower developers in their Git journey. Whether you're a beginner or looking to reinforce your Git skills, this quick reference offers insights into key commands for collaboration and efficient code management.

Git Image

Clone a Repository:

git clone https://github.com/example/repo.git

Download a copy of a remote repository to your local machine.


Initialize a New Repository:

git init

Creates a new Git repository in the current directory.


Add Changes to Staging Area:

git add file1.txt file2.js

Adds changes made to files to the staging area, preparing them for a commit.


Commit Changes:

git commit -m "Added new features"

Records changes made to files in the repository with a descriptive commit message.


Check Status:

git status

Shows the current status of your working directory, including changes not yet committed.


View Commit History:

git log

Displays a log of all commits made in the repository.


Create a New Branch:

git branch feature-branch

Creates a new branch in the repository.


Switch to a Branch:

git checkout feature-branch

Changes the working directory to the specified branch.


Create and Switch to a New Branch:

git checkout -b new-feature

Combines branch creation and switching into a single command.


Merge Branches:

git merge feature-branch

Combines changes from one branch into another.


Pull Changes from a Remote Repository:

git pull origin main

Fetches changes from a remote repository and merges them into the current branch.


Push Changes to a Remote Repository:

git push origin new-feature

Uploads local commits to a remote repository.


Fetch Changes from a Remote Repository:

git fetch origin

Downloads change from a remote repository without merging them into the local branch.


Undo Changes in the Working Directory:

git checkout -- file1.txt

Discards changes made to files in the working directory.


Undo Changes in the Staging Area:

git reset HEAD file2.js

Unstaged changes from the staging area, keeping them in the working directory.


Discard Local Changes:

git reset --hard

Discards all changes in the working directory and staging area.


Configure User Information:

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

Sets the user name and email to be associated with commits.




Comments

Free Harvard Inspired Resume Template