QA notes for freshers · Git and GitHub

Git and GitHub for Beginners

Every software team uses Git. As a tester you will store and share your automation code with it.

1. What are Git and GitHub?

Simple idea: Git is like "save history" in a game, and GitHub is the cloud where the team keeps the shared save.

2. Words you must know

TermMeaning
Repository (repo)A project folder tracked by Git.
CommitA saved snapshot of your changes, with a message.
BranchA separate line of work. You can change code safely without touching the main code.
main (master)The main, stable branch.
Remote / originThe online copy of the repo (on GitHub). "origin" is its default nickname.
CloneDownload a full copy of a remote repo to your computer.
ForkYour own personal copy of someone else's repo on GitHub.
Pull request (PR)A request to merge your branch into main. Teammates review it first.
MergeCombining one branch's changes into another.
Merge conflictTwo people changed the same lines; Git cannot decide, so you choose manually.
Staging areaWaiting room where you place changes before committing.

3. How the work flows

Working folder→ git add →Staging area→ git commit →Local repo→ git push →GitHub (remote)

And in the other direction, git pull brings the latest changes from GitHub to your computer.

4. First-time setup

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

What it does: tells Git who you are. This name and email appear on every commit you make. Do it once per computer.

5. Commands you will use daily

CommandWhat it does
git clone <url>Download a repo from GitHub.
git statusShow which files changed. Use it often.
git add file.javaPut one file in staging. git add . adds all changed files.
git commit -m "message"Save staged changes with a message.
git pushUpload your commits to GitHub.
git pullDownload and merge the latest changes from GitHub.
git log --onelineShow the commit history in short form.
git diffShow exactly what lines you changed.
git fetchDownload remote changes but do not merge yet.

Branch commands

CommandWhat it does
git branchList branches.
git checkout -b feature/login-testsCreate a new branch and move to it. (git switch -c does the same.)
git checkout mainMove to an existing branch. (git switch main also works.)
git merge feature/login-testsMerge that branch into the branch you are on.
git branch -d feature/login-testsDelete a branch you no longer need.

Undo and save-for-later commands

CommandWhat it does
git restore file.javaThrow away your unsaved changes in that file.
git restore --staged file.javaRemove a file from staging, keep your changes.
git commit --amendFix the last commit message or add a forgotten file (only before pushing).
git revert <commit-id>Safely undo an old commit by making a new opposite commit.
git stash / git stash popTemporarily keep unfinished work aside, then bring it back.
Be careful with git reset --hard. It deletes your changes permanently. Ask a senior before using it.

6. A normal working day

git checkout main
git pull
git checkout -b feature/add-search-tests
# ... write your test code ...
git status
git add .
git commit -m "Add search page automation tests"
git push -u origin feature/add-search-tests

Step by step: go to main → get the latest code → make your own branch → work → check what changed → stage the files → commit with a clear message → push the branch to GitHub (-u links your local branch to the remote one, needed only the first time). Then open GitHub and create a pull request.

7. Pull request (PR) process

  1. Push your branch and click "Compare & pull request" on GitHub.
  2. Write a short title and description of what you changed.
  3. Teammates review and may leave comments. You fix them and push again; the PR updates itself.
  4. After approval (and passing automatic checks), the PR is merged into main.

8. Merge conflict

When Git cannot merge automatically, it marks the file like this:

<<<<<<< HEAD
String url = "https://qa.example.com";
=======
String url = "https://staging.example.com";
>>>>>>> feature/add-search-tests

How to fix: the top part is your current branch, the bottom part is the incoming branch. Keep the right line (or combine both), delete the <<<<<<<, =======, >>>>>>> lines, then run git add and git commit.

9. Good habits

10. How testers use Git

11. More commands and ideas

Starting a project from scratch

git init
git remote add origin https://github.com/yourname/qa-project.git
git branch -M main
git push -u origin main

What it does: init makes the folder a Git repo → connects it to an empty GitHub repo called origin → names the branch main → uploads the first commits.

Three kinds of reset

CommandCommitStagingYour files
git reset --soft HEAD~1UndoneKeptKept
git reset --mixed HEAD~1UndoneClearedKept
git reset --hard HEAD~1UndoneClearedLost

HEAD means the commit you are on now. HEAD~1 means one commit before it. Use reset only on commits you have not pushed. For pushed commits use git revert.

Other useful commands

CommandWhat it does
git remote -vShow the remote URLs.
git cherry-pick <commit-id>Copy one particular commit onto your current branch.
git tag v1.0Mark a commit with a name, such as a release.
git blame file.javaShow who changed each line and when.
git show <commit-id>Show the details of one commit.
git rebase mainMove your branch's commits on top of the latest main.
git branch -aList local and remote branches.
git log --oneline --graphHistory with a branch drawing.

Merge vs rebase

.gitignore example

target/
.idea/
*.log
screenshots/
config/secrets.properties

What it does: Git will skip the build folder, IDE settings, log files, screenshots and a secrets file. Files already committed must be removed with git rm --cached first.

HTTPS vs SSH for GitHub

HTTPS asks for a username and a personal access token. SSH uses a key pair saved once on your computer, so you do not type anything again. Use ssh-keygen to create the key and add the public key to GitHub settings.

12. Branching strategy in companies

BranchPurpose
mainStable, ready-for-release code.
developWhere the team's finished features come together for testing.
feature/xyzOne new feature or one set of tests.
bugfix/xyzA fix for a bug.
hotfix/xyzA quick fix straight from main for a live problem.
release/1.2Final stabilizing before a version is released.

13. GitHub features you will see

name: Run tests
on: [push, pull_request]
jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-java@v4
        with: { java-version: '17', distribution: 'temurin' }
      - run: mvn test

What it does: on every push or pull request, GitHub starts a fresh machine → downloads your code → sets up Java 17 → runs mvn test. If a test fails, the PR shows a red cross. This is basic CI (Continuous Integration). Jenkins does the same job on your own server.

CI vs CD

CI (Continuous Integration): code is built and tested automatically on every change. CD (Continuous Delivery/Deployment): after tests pass, the app is released to an environment automatically or with one click.

14. Quick interview answers