Git commands are essential for DevOps engineers to ensure version control, streamline collaboration, automate infrastructure management, and facilitate CI/CD processes. Mastery of Git empowers DevOps teams to deliver high-quality software and infrastructure efficiently and reliably.
Git commands as a devops engineer you should know ?
Initialize a New Repository:
git init:
Creates a new Git repository in your project directory.git init
Clone a Remote Repository:
git clone <repository_url>
: Creates a local copy of a remote Git repository.git clone <repository_url>
Staging Changes:
git add <file>
: Adds specific files to the staging area for the next commit.git add <file>
git status
: Shows which files are modified, staged, or untracked.git status
Commit Changes:
git commit -m "Your commit message"
: Records changes with a meaningful message.git commit -m "Your commit message"
git commit -a
: Commits any files you’ve added with git add and also commits any files you’ve changed since then.git commit -a
View History and Logs:
git log
: Displays the history of your project, including commit messages and authors.git log
git show <commit>
: Shows metadata and content changes for a specific commit.git show <commit>
Branching and Merging:
git branch <branch_name>
: Creates a new branch for specific tasks.git branch <branch_name>
git checkout <branch_name>
: Switches to a different branch.git checkout <branch_name>
git merge <branch_name>
: Merges changes from one branch into another.git merge <branch_name>
Remote Repositories:
git remote add <name> <repository_url>
: Adds a remote repository.git remote add <name> <repository_url>
git push <remote_name> <branch_name>
: Pushes changes to a remote repository.git push <remote_name> <branch_name>
git pull <remote_name> <branch_name>
: Pulls changes from a remote repository.git pull <remote_name> <branch_name>
Comparison and Diff:
git diff
: Shows file differences not yet staged.git diff
git diff --staged
: Shows differences between files in the staging area and the latest version.git diff --staged
git diff <first_branch> <second_branch>
: Compares differences between two branches.git diff <first_branch> <second_branch>
Undoing Changes:
git reset <file>
: Unstages a file while preserving its contents.git reset <file>
git reset <commit>
: Undoes all commits after the specified commit.git reset <commit>
git reset --hard <commit>
: Discards all history and goes back to the specified commit.git reset --hard <commit>
Tagging:
git tag <commit ID>
: Gives tags to a specific commit.git tag <commit ID>
Remember, Git allows you to track every change made in your project, collaborate with other developers, and efficiently manage code modifications. Happy coding! 🚀👩💻