Git is a distributed version control system that tracks changes in source code and enables collaboration among developers.
Every DevOps engineer is expected to master Git — it’s the foundation of CI/CD pipelines and modern software collaboration.
With Git, engineers can:
Common platforms: GitHub, GitLab, Bitbucket, AWS CodeCommit.
Answer:
GitHub is a cloud-based platform built on top of Git that provides hosting for repositories, collaboration tools, and features like pull requests and issue tracking.
In DevOps:
Git is installed locally to manage code, while GitHub or GitLab acts as a remote central repository for team collaboration and integration into CI/CD pipelines.
git clone, git pull, and git fetch?Answer:
git clone: Creates a copy of a remote repository on your local machine (used the first time you set up). git fetch: Downloads changes from the remote repository but does not merge them into your local branch. git pull: Fetches and automatically merges remote changes into your current branch.Example in DevOps:
In CI/CD jobs, Jenkins often uses git fetch to check for changes before triggering a build.
Answer:
After editing files, you must stage and commit them.
Staging allows you to prepare specific files for the next commit, while committing saves the changes to the local repository history.
Answer:
A branch is an independent line of development that allows multiple developers to work in parallel.
main (or master) → stable production codefeature/login → feature under developmentbugfix/payment → bug fix branchCommands:
In DevOps:
Branches isolate development work from production code — crucial for automated deployments and version control in CI/CD.
Answer:
Shows all commits with author, date, and message.
For a concise view:
Why it’s important:
Understanding commit history helps during troubleshooting, audits, and rollback planning in production environments.
.gitignore and why is it used?Answer:
A .gitignore file tells Git which files or folders to exclude from version control.
Example:
Use in DevOps:
This prevents unnecessary or sensitive files (API keys, environment variables, binaries) from being uploaded to repositories — a crucial security practice.
Answer:
Displays:
Example output:
git merge and git rebase?Answer:
git merge combines changes from one branch into another and preserves both commit histories.git rebase integrates changes by rewriting commit history to make it linear.Example:
In CI/CD:
Teams use rebase to keep commit history clean and merge to maintain a detailed history of collaboration.
Answer:
If you haven’t pushed yet:
This removes the last commit but keeps changes staged.
To completely discard:
DevOps tip:
Use reset carefully — it rewrites commit history, which can affect team synchronization.
git stash and git commit?Answer:
git stash: Temporarily saves uncommitted changes without committing them.git commit: Permanently records changes in history.Example:
Use case:
During a deployment fix, you might stash local changes to quickly switch branches and return later without losing work.
Answer:
A Pull Request (PR) is a request to merge code from one branch (usually feature) into another (like main).
It includes:
Why it matters:
Pull requests ensure that only reviewed, tested, and approved code reaches production — critical for stable releases.
Answer:
A merge conflict happens when two branches modify the same part of a file differently.
Steps to resolve:
Git marks conflict areas like:
Manually edit to keep the correct version.
Stage and commit:
DevOps scenario:
Merge conflicts often occur when multiple developers push config files or Jenkinsfiles simultaneously.
origin and upstream?Answer:
Example:
Use in DevOps:
Helps when contributing to open-source or managing internal forks for enterprise CI/CD projects.
Answer:
Tags are used to mark important points in history (e.g., production releases).
Example:
Why it’s important:
Tags integrate with CI/CD tools (like Jenkins or CodePipeline) to trigger deployments for specific versions.
Answer:
Use:
This creates a new commit that undoes the changes without rewriting history.
In DevOps:
This is preferred over reset for production repos because it’s safe and traceable.
Answer:
A branching strategy defines how teams manage branches for features, releases, and hotfixes.
Common strategies:
develop, feature, release, and hotfix.main, open PRs, and merge after review.main) with frequent merges.Why it matters:
Branching strategy impacts CI/CD efficiency and release management discipline.
Answer:
Jenkins or GitHub Actions clones the repository:
Pulls the latest code (git pull) on each build.
Checks out a branch for deployment:
Triggers build, test, and deploy stages automatically.
Benefit:
Git ensures source of truth consistency — pipelines deploy exactly what’s versioned in the repository.
Answer:
or between branches:
In CI/CD:
Used in pre-deployment scripts to identify which files changed since the last deployment (useful for incremental updates).
Answer:
Why it matters:
Cleaning up branches prevents clutter and confusion in large-scale team projects.
Answer:
Never commit secrets directly!
Use:
.gitignore to exclude .env or config files.Example:
Instead of hardcoding credentials in a script:
Answer:
If a deployment introduced a bug:
Identify the last stable commit:
Revert to that commit:
Push the revert commit and redeploy:
DevOps workflow:
Rollback scripts in pipelines often automate this process to restore system stability quickly.
Answer:
Squashing merges multiple commits into one to simplify history.
Example:
Replace pick with squash for the commits you want to combine.
When used:
Before merging a feature branch to main, squash commits to keep history clean — especially in enterprise CI/CD environments.
git cherry-pick and git revert?Answer:
git cherry-pick: Copies a commit from one branch to another.main to develop.git revert: Creates a new commit that undoes changes from a previous commit.In DevOps:
Useful for emergency patching or backporting critical changes.
Answer:
Git hooks are scripts that automatically run when certain Git events occur (like commit or push).
Located in .git/hooks/.
Example: pre-commit, post-commit, pre-push.
Example use:
Prevents committing if tests fail.
In CI/CD:
Hooks are used to enforce quality gates (linting, tests) before merging code.
Answer:
Use BFG Repo-Cleaner or git filter-branch.
Example:
Then force-push cleaned history:
DevOps impact:
Accidentally committing secrets can expose credentials in CI/CD logs — cleaning history is part of secure repository hygiene.
git reset, git revert, and git restore?Answer:
| Command | Description | Safe for Shared Repo? |
|---|---|---|
git reset |
Moves HEAD and optionally modifies index & working directory. | No (rewrites history) |
git revert |
Creates new commit that undoes changes. | Yes |
git restore |
Restores working directory files. | Yes |
Example:
Undo local changes without touching commits.
Answer:
main, breaking the production pipeline. What did you do?main, triggering failed builds and downtime on staging.Action:
Used git log to find the merge commit.
Ran git revert -m 1 <merge_commit_id> to undo the merge safely.
Pushed the fix and re-triggered the Jenkins build.
Opened a follow-up PR with corrected code after testing.
Result:
Production was restored within 10 minutes, with no rollback required. The team later enforced branch protection rules to prevent unreviewed merges.
Situation:
During a Jenkins deployment, we found AWS credentials hardcoded in a committed config file pushed to GitHub.
Task:
Remove the secrets immediately and secure the environment.
bfg --delete-files "*.env" to clean Git history..env to .gitignore.truffleHog) to prevent recurrence.