Essential Linux Commands for Git Terminal

πŸ“ 1. File & Directory Navigation

1. pwd

Description: Shows the current working directory path.

pwd

2. ls

Description: Lists files and directories.

ls
ls -la # detailed list including hidden files

3. cd

Description: Changes directory.

cd project-folder
cd .. # move up one directory
cd ~ # go to home directory

πŸ“‚ 2. File & Directory Management

4. mkdir

Description: Creates a new directory.

mkdir my-repo

5. rmdir

Description: Removes an empty directory.

rmdir my-repo

6. rm

Description: Deletes files or directories.

rm file.txt
rm -r folder/ # remove directory recursively

7. cp

Description: Copies files or directories.

cp file.txt backup.txt
cp -r folder/ new-folder/

8. mv

Description: Moves or renames files.

mv file.txt newname.txt
mv file.txt folder/

πŸ“ 3. File Viewing & Editing

9. cat

Description: Displays file content.

cat README.md

10. less

Description: Views large files page by page.

less README.md

11. nano

Description: Simple terminal text editor.

nano file.txt

12. vim

Description: Advanced text editor.

vim file.txt

πŸ” 4. Search & Filtering

13. grep

Description: Searches text in files.

grep "function" file.js

14. find

Description: Finds files/directories.

find . -name "index.js"

βš™οΈ 5. Permissions & Ownership

15. chmod

Description: Changes file permissions.

chmod 755 script.sh

16. chown

Description: Changes file ownership.

chown user:user file.txt

🌐 6. Networking (Useful for Git)

17. ssh

Description: Connects securely to remote servers (used for GitHub SSH).

ssh -T git@github.com

18. curl

Description: Transfers data from URLs.

curl https://api.github.com

🧰 7. Archive & Compression

19. tar

Description: Creates/extracts archives.

tar -cvf project.tar folder/
tar -xvf project.tar

20. zip / unzip

Description: Compresses and extracts zip files.

zip -r project.zip folder/
unzip project.zip

πŸ§ͺ 8. System & Process Commands

21. clear

Description: Clears the terminal screen.

clear

22. history

Description: Shows previously used commands.

history

23. top

Description: Displays running processes.

top

πŸ”„ How These Help in Git Workflow

When working with Git, these Linux commands help you:

  • Navigate to repositories (cd, ls)
  • Create/manage project files (mkdir, rm, cp)
  • Edit code before committing (nano, vim)
  • Inspect changes (cat, less)
  • Search code (grep, find)
  • Handle SSH authentication (ssh)

πŸš€ Example Git Workflow with Linux Commands

mkdir my-project
cd my-project
git inittouch README.md
nano README.mdgit add .
git commit -m "Initial commit"

Github Interview Questions And Answers

1. What is GitHub? How is it different from Git?

πŸ‘‰ Answer:

  • Git is a distributed version control system used to track code changes.
  • GitHub is a cloud-based platform that hosts Git repositories and adds collaboration features.

πŸ‘‰ Use Case:
In a team project, developers use Git locally and push code to GitHub for collaboration, reviews, and CI/CD.


2. What is a Repository?

πŸ‘‰ Answer:
A repository (repo) is a storage space for your project that contains code, files, and version history.

πŸ‘‰ Use Case:
You create a repo for a Playwright automation project where all test scripts, configs, and reports are stored.


3. What is the difference between Fork and Clone?

πŸ‘‰ Answer:

  • Fork: Copy of someone else’s repo into your GitHub account.
  • Clone: Copy of a repo to your local machine.

πŸ‘‰ Use Case:

  • Fork: Contributing to open-source.
  • Clone: Working on your team project locally.

4. What is a Branch?

πŸ‘‰ Answer:
A branch is a separate line of development.

πŸ‘‰ Use Case:
You create:

  • main β†’ production code
  • feature/login-test β†’ new feature work

5. What is a Pull Request (PR)?

πŸ‘‰ Answer:
A PR is a request to merge changes from one branch to another.

πŸ‘‰ Use Case:
QA automation engineer raises a PR after adding test cases β†’ Developer reviews β†’ merges into main.


6. What is Merge Conflict?

πŸ‘‰ Answer:
Occurs when Git cannot automatically merge changes.

πŸ‘‰ Use Case:
Two developers modify the same file β†’ conflict β†’ manually resolved before merge.


7. What is GitHub Actions?

πŸ‘‰ Answer:
A CI/CD tool in GitHub used to automate workflows.

πŸ‘‰ Use Case:

  • Run Playwright tests automatically on every PR
  • Deploy app after merge

8. What is .gitignore?

πŸ‘‰ Answer:
A file that specifies which files Git should ignore.

πŸ‘‰ Use Case:
Ignore:

  • node_modules/
  • test-results/
  • .env

9. What is Git Workflow (Branching Strategy)?

πŸ‘‰ Answer:
A process defining how teams use branches.

πŸ‘‰ Common strategies:

  • Git Flow
  • Feature Branch Workflow

πŸ‘‰ Use Case:

  • Create feature branch
  • Push code
  • Raise PR
  • Review β†’ Merge

10. What is Staging in Git?

πŸ‘‰ Answer:
Intermediate area before committing changes.

πŸ‘‰ Commands:

git add .
git commit -m "message"

πŸ‘‰ Use Case:
You selectively add only required files before committing.


11. Difference between Commit and Push?

πŸ‘‰ Answer:

  • Commit: Save changes locally
  • Push: Upload changes to GitHub

πŸ‘‰ Use Case:
You commit multiple times locally β†’ push once after testing.


12. What is Rebase vs Merge?

πŸ‘‰ Answer:

  • Merge: Keeps history (creates merge commit)
  • Rebase: Rewrites history (linear)

πŸ‘‰ Use Case:
Rebase keeps clean commit history before merging feature branch.


13. What is Tag in Git?

πŸ‘‰ Answer:
A tag marks a specific version of code.

πŸ‘‰ Use Case:
Mark releases like:

v1.0
v2.0

14. What is Git Stash?

πŸ‘‰ Answer:
Temporarily saves uncommitted changes.

πŸ‘‰ Use Case:
You are working on a feature but need to switch branches quickly.


15. What is Code Review in GitHub?

πŸ‘‰ Answer:
Process of reviewing code before merging.

πŸ‘‰ Use Case:

  • Developer checks logic
  • QA verifies test coverage
  • Ensures code quality

πŸ”Ή Scenario-Based GitHub Interview Questions


16. You pushed wrong code to main branch. What will you do?

πŸ‘‰ Answer:

  • Revert commit:
git revert <commit-id>

OR

  • Reset (if safe):
git reset --hard HEAD~1

πŸ‘‰ Best Practice:
Avoid direct commits to main β†’ use PR workflow.


17. Multiple developers working on same feature. How to manage?

πŸ‘‰ Answer:

  • Use feature branches
  • Regularly pull latest changes
  • Resolve conflicts early

πŸ‘‰ Use Case:
Each dev works on sub-features β†’ merged via PR.


18. How do you handle large files in GitHub?

πŸ‘‰ Answer:
Use Git LFS (Large File Storage).

πŸ‘‰ Use Case:
Store large test data or binaries.


19. How do you secure sensitive data in GitHub?

πŸ‘‰ Answer:

  • Never commit secrets
  • Use GitHub Secrets
  • Use .gitignore

πŸ‘‰ Use Case:
Store API keys in environment variables.


20. Explain CI/CD pipeline using GitHub Actions

πŸ‘‰ Answer:

  1. Code pushed to GitHub
  2. Workflow triggers
  3. Build runs
  4. Tests execute
  5. Deploy

πŸ‘‰ Use Case:
Playwright tests run automatically on every commit.


πŸ”Ή Advanced Practical Questions


21. How do you revert a specific file to previous version?

git checkout <commit-id> -- file.js

22. How do you squash commits?

git rebase -i HEAD~3

πŸ‘‰ Combine multiple commits into one.


23. What is Detached HEAD?

πŸ‘‰ Answer:
When you’re not on any branch.

πŸ‘‰ Use Case:
Checking old commit without affecting current branch.


24. How do you delete a branch?

git branch -d branch-name
git push origin --delete branch-name

25. What is Upstream in Git?

πŸ‘‰ Answer:
Reference to original repository (especially in forks).

πŸ‘‰ Use Case:
Keep your fork updated with original repo.


Mock Interview: GitHub (Real Company Style)


πŸ”Ή Round 1: Basics + Practical Understanding

❓ Q1: Explain your GitHub workflow in your current project.

πŸ‘‰ Strong Answer:

β€œWe follow a feature branch workflow. Each task starts with a new branch from main. After development, we push code and raise a pull request. CI runs automatically using GitHub Actions. After code review and approvals, we merge into main. Direct commits to main are restricted.”

πŸ‘‰ What interviewer checks:

  • Real experience
  • Collaboration understanding
  • CI/CD awareness

❓ Q2: What happens when you run git push?

πŸ‘‰ Strong Answer:

β€œIt uploads local commits from my machine (using Git) to the remote repository on GitHub, making them available to the team.”

πŸ‘‰ Follow-up trap:
πŸ‘‰ β€œWhat if push is rejected?”

βœ”οΈ Answer:

β€œIt usually means my branch is behind. I pull the latest changes, resolve conflicts if any, and push again.”


πŸ”Ή Round 2: Scenario-Based Questions


❓ Q3: You and another developer changed the same file. Your PR shows conflict. What do you do?

πŸ‘‰ Strong Answer:

β€œI pull the latest changes from main, resolve conflicts locally, test the code, commit the fix, and push again to update the PR.”

πŸ‘‰ Bonus point:
Mention testing after conflict resolution.


❓ Q4: You accidentally pushed sensitive data (API key) to GitHub. What will you do?

πŸ‘‰ Strong Answer:

β€œFirst, I revoke the key immediately. Then I remove it from the repository, rewrite history if needed, and ensure it’s added to .gitignore. Going forward, I store secrets using GitHub Secrets.”

πŸ‘‰ What interviewer checks:

  • Security awareness
  • Real-world handling

❓ Q5: Your teammate’s PR broke the build. What should happen?

πŸ‘‰ Strong Answer:

β€œThe CI pipeline should fail automatically. The PR should not be merged until the issue is fixed. We enforce required checks before merging.”

πŸ‘‰ Extra credit:
Mention branch protection rules.


πŸ”Ή Round 3: CI/CD + Automation (Very Important)


❓ Q6: How do you integrate automation tests with GitHub?

πŸ‘‰ Strong Answer:

β€œWe use GitHub Actions to trigger Playwright tests on every PR. The workflow installs dependencies, runs tests, and publishes reports.”

πŸ‘‰ Example flow:

  • PR created
  • Tests run automatically
  • Pass β†’ merge allowed
  • Fail β†’ fix required

❓ Q7: How do you ensure code quality before merging?

πŸ‘‰ Strong Answer:

β€œWe use a combination of:

  • Pull request reviews
  • Automated tests
  • Linting checks
  • CI validation

Only after all checks pass, the PR is merged.”


πŸ”Ή Round 4: Advanced Problem Solving


❓ Q8: Your main branch is broken after a merge. What will you do?

πŸ‘‰ Strong Answer:

β€œI would quickly identify the faulty commit and revert it using git revert. Then fix the issue in a new branch and raise another PR.”

πŸ‘‰ Important:
Avoid rewriting history in shared branches.


❓ Q9: How do you handle multiple environments (dev, staging, prod)?

πŸ‘‰ Strong Answer:

β€œWe use different branches or deployment workflows. For example:

  • develop β†’ dev environment
  • main β†’ production
    CI/CD pipelines deploy automatically based on branch.”

❓ Q10: How do you manage large teams working on the same repo?

πŸ‘‰ Strong Answer:

β€œWe use:

  • Feature branches
  • Clear naming conventions
  • Code owners
  • Mandatory PR reviews
  • CI/CD checks

This ensures smooth collaboration and avoids conflicts.”


πŸ”Ή Round 5: Rapid Fire (Quick Checks)


❓ Difference between Fork and Clone?

πŸ‘‰ Fork = copy on GitHub
πŸ‘‰ Clone = copy on local machine


❓ What is HEAD in Git?

πŸ‘‰ Pointer to the current commit/branch


❓ What is Rebase?

πŸ‘‰ Rewrites commit history to make it linear


❓ What is Stash?

πŸ‘‰ Temporarily saves uncommitted changes


❓ What is a Tag?

πŸ‘‰ Marks a release/version


πŸ”Ή Real Interview Challenge (Hands-On Thinking)


❓ Q11: Design a GitHub workflow for automation testing.

πŸ‘‰ Strong Answer:

β€œI would:

  1. Trigger workflow on PR and push
  2. Install dependencies
  3. Run Playwright tests
  4. Generate reports
  5. Upload artifacts
  6. Fail build if tests fail

This ensures only tested code gets merged.”


πŸ”Ή Final HR + Practical Question


❓ Q12: Tell me a real problem you faced in GitHub and how you solved it.

πŸ‘‰ Sample Answer:

β€œWe had frequent merge conflicts due to long-running branches. I suggested smaller PRs and frequent rebasing. This reduced conflicts and improved deployment speed.”



GitHub Fundamentals

1. What is GitHub?

  • GitHub is a platform to store, manage, and collaborate on code.
  • It uses Git (a version control system).

πŸ‘‰ Think of GitHub as:

β€œGoogle Drive for code + collaboration tools for developers”


2. What is Git?

  • Git tracks changes in your code.
  • Helps you:
    • Save versions
    • Undo mistakes
    • Work with teams

3. Repository (Repo)

A repository is a project folder stored on GitHub.

Example:

my-project/
β”œβ”€β”€ index.html
β”œβ”€β”€ style.css
└── script.js

πŸ‘‰ This entire folder = 1 repository


4. Clone a Repository

Copy a GitHub repo to your local machine.

Command:

git clone https://github.com/user/project.git

Example:

git clone https://github.com/deepesh/my-app.git

5. Basic Git Workflow

The most important concept πŸ‘‡

Working Directory β†’ Staging Area β†’ Repository

Steps:

git add file.js      # Add file to staging
git commit -m "Added feature" # Save changes
git push # Upload to GitHub

6. Commit

A commit is a snapshot of your code.

Example:

git commit -m "Fixed login bug"

πŸ‘‰ Good commit message = clear + meaningful


7. Branch

A branch lets you work on features without affecting main code.

Example:

git branch feature-login
git checkout feature-login

Or shortcut:

git checkout -b feature-login

8. Merge

Combine changes from one branch into another.

Example:

git checkout main
git merge feature-login

9. Pull Request (PR)

  • A Pull Request is used to merge code on GitHub.
  • You request others to review your code.

πŸ‘‰ Workflow:

  1. Create branch
  2. Push code
  3. Open PR
  4. Review β†’ Merge

10. Push & Pull

Push (upload changes):

git push origin main

Pull (get latest changes):

git pull origin main

11. Fork

A fork is a copy of someone else’s repository.

πŸ‘‰ Used in open-source contributions.


12. .gitignore

Tells Git which files to ignore.

Example:

node_modules/
.env
*.log

13. Real Example Workflow

Let’s say you’re building a JavaScript project:

Step 1: Initialize repo

git init

Step 2: Add files

git add .

Step 3: Commit

git commit -m "Initial project setup"

Step 4: Connect GitHub

git remote add origin https://github.com/user/project.git

Step 5: Push

git push -u origin main

14. Common Commands Cheat Sheet

CommandPurpose
git initStart repo
git cloneCopy repo
git addStage changes
git commitSave changes
git pushUpload
git pullDownload updates
git branchList branches
git checkoutSwitch branch

15. Best Practices

  • βœ… Commit often
  • βœ… Use clear commit messages
  • βœ… Use branches for features
  • βœ… Pull before push
  • ❌ Don’t push sensitive data

🎯 Mini Practice Exercise

Try this:

  1. Create a folder
  2. Add a file app.js
  3. Run:
  4. Push it to GitHub
git init
git add .
git commit -m "First commit"
git push

Pro Tip

Start with:

  • Personal projects
  • Practice branching + PRs

That’s how real developers learn GitHub fast.

16. GitHub Issues (Task Tracking)

  • Issues are used to track bugs, tasks, or feature requests.

Example:

You create an issue:

Title: Fix login error
Description: Login fails when password is incorrect

πŸ‘‰ You can:

  • Assign team members
  • Add labels (bug, feature, urgent)
  • Track progress

πŸ“Œ 17. Labels (Organizing Work)

Labels help categorize issues.

Example labels:

  • bug πŸ›
  • enhancement πŸš€
  • documentation πŸ“„

πŸ‘‰ Helps teams quickly understand task types.


πŸ“Š 18. GitHub Projects (Kanban Board)

GitHub provides project boards similar to Trello.

Example workflow:

To Do β†’ In Progress β†’ Done

πŸ‘‰ You can drag issues between columns.


πŸ” 19. README.md File

This is the first file people see in your repo.

Example:

# My AppThis is a simple JavaScript project.## Features
- Login system
- Dashboard

πŸ‘‰ A good README increases project visibility.


βš™οΈ 20. GitHub Actions (Automation)

  • GitHub Actions lets you automate workflows.

Example:

Run tests automatically when code is pushed.

name: Test App
on: [push]jobs:
test:
runs-on: ubuntu-latest
steps:
- run: echo "Running tests..."

πŸ‘‰ Used for:

  • CI/CD (Continuous Integration / Deployment)
  • Auto testing
  • Deployment

πŸ” 21. Pull vs Fetch

Git Pull:

git pull origin main

πŸ‘‰ Fetch + merge

Git Fetch:

git fetch

πŸ‘‰ Only downloads changes (no merge)


πŸ”„ 22. Merge Conflict (Important!)

Occurs when Git can’t merge automatically.

Example conflict:

<<<<<<< HEAD
console.log("Hello");
=======
console.log("Hi");
>>>>>>> branch

πŸ‘‰ You must manually fix it:

console.log("Hello Hi");

Then:

git add .
git commit -m "Resolved conflict"

πŸ§ͺ 23. Stash (Temporary Save)

Save changes without committing.

git stash

Restore:

git stash pop

πŸ‘‰ Useful when switching branches quickly.


πŸ“œ 24. Git Log (History)

View commit history:

git log

Short version:

git log --oneline

βͺ 25. Undo Changes

Undo staged file:

git reset file.js

Undo last commit:

git reset --soft HEAD~1

Discard changes:

git checkout -- file.js

🌐 26. Remote Repository

Link your local repo to GitHub.

git remote add origin https://github.com/user/repo.git

Check:

git remote -v

πŸ”’ 27. SSH vs HTTPS

Two ways to connect GitHub:

HTTPS:

https://github.com/user/repo.git

SSH:

git@github.com:user/repo.git

πŸ‘‰ SSH is more secure (no need to enter password repeatedly)


πŸ“¦ 28. Fork + Clone + PR (Real Open Source Flow)

Step-by-step:

  1. Fork repository on GitHub
  2. Clone it:
git clone https://github.com/your-username/repo.git
  1. Create branch:
git checkout -b fix-bug
  1. Make changes + commit
  2. Push:
git push origin fix-bug
  1. Create Pull Request

πŸ‘‰ This is how open-source contributions work.


🧱 29. Rebase (Advanced Concept)

Instead of merge, you can use rebase for cleaner history.

git checkout feature
git rebase main

πŸ‘‰ Keeps history linear (no extra merge commits)


🏷️ 30. Tags (Versioning)

Used for releases.

git tag v1.0
git push origin v1.0

πŸ‘‰ Example:

  • v1.0 β†’ first release
  • v2.0 β†’ major update

Real-World Scenario (Important)

Scenario: Team Development

  1. Developer A creates feature branch
  2. Developer B works on another branch
  3. Both create Pull Requests
  4. Code review happens
  5. Merge into main

πŸ‘‰ This prevents breaking the main codebase.


🧠 Pro Learning Tips

  • Practice daily with small repos
  • Break code β†’ fix using Git
  • Try merge conflicts intentionally
  • Explore open-source repos

πŸ’» Practice Tasks (Next Level)

Try these:

  1. Create 2 branches and merge them
  2. Create a merge conflict and resolve it
  3. Use git stash while switching branches
  4. Create a Pull Request on your own repo
  5. Add a README with project details