Master the Basics: A Git Cheat Sheet for QA Testers

Rakesh Kamaraju
4 min readMay 7, 2023

--

As a technical tester, working with Git is an integral part of your daily routine. Mastering the basic Git commands can streamline your workflow and make collaboration more efficient. In this comprehensive Git Cheat Sheet, we will cover the most common Git commands you’ll need to know for your day-to-day work.

Table of Contents:

  1. Initial Git Setup
  2. Git Branch
  3. Git Staging
  4. Git Status
  5. Git Commits
  6. Git Push
  7. Git Fetch and Pull
  8. Git Merging and Rebasing

Step 1: Initial Git Setup

Before you can use Git, you’ll need to initialize a repository or clone an existing one. Here’s how you can do that:

  • To initialize a new Git repo: $ git init
  • To clone an existing repo: $ git clone https://github.com/<username>/<repo-name>.git <local-folder-name>

Step 2: Git Branch

When working on a new feature or bugfix, creating a new branch in Git is essential. Here’s how you can create, list, switch, and delete branches:

  • To create a new branch: $ git checkout -b <new-branch-name>
  • To list all available branches: $ git branch
  • To switch to a different branch: $ git checkout <branch-name>
  • To delete a local branch: $ git branch -d <branch-name>
  • To delete a remote branch on origin: $ git push origin --delete <remote-branch-name>

Step 3: Git Staging

Staging is the process of preparing changes for a commit. Here’s how you can stage and unstage files in Git:

  • To stage individual files: $ git add <file-name>
  • To stage all files at once: $ git add .
  • To unstage a file: $ git reset HEAD <file-name>
  • To unstage all files: $ git reset HEAD .

Step 4: Git Status

Git status provides a report on what files have been created, modified, or deleted. Here’s how you can use Git status:

  • To check the status of your repo: $ git status

Step 5: Git Commits

Committing your changes often is a best practice. Here’s how you can commit, undo, and squash commits in Git:

  • To commit your changes: $ git commit -m "<commit-message>"
  • To undo your most recent commit and put those changes back into staging: $ git reset --soft HEAD~1
  • To completely delete the commit and discard any changes: $ git reset --hard HEAD~1
  • To squash multiple commits into one: $ git rebase -i HEAD~<num-of-commits>

Step 6: Git Push

Once you’ve committed your changes, you’ll want to push them to a remote repository. Here’s how you can push your changes to a remote repo:

  • To push a local branch for the first time: $ git push --set-upstream origin <branch-name>
  • To push a local branch to a different remote branch: $ git push origin <local-branch-name>:<remote-branch-name>
  • To undo your last push: $ git reset --hard HEAD~1 && git push -f origin <branch-name>

Step 7: Git Fetch and Pull

Git fetch allows you to keep your repository up-to-date without merging other commits with your current branch. Git pull, on the other hand, merges other commits automatically. Here’s how you can fetch and pull changes in Git:

  • To fetch changes from upstream: $ git fetch upstream
  • To pull a specific branch: $ git pull origin <branch-name>
  • To pull all changes and all other branches: $ git pull

Step 8: Git Merging and Rebasing

Merging and rebasing allow you to integrate changes from one branch into another. Here’s how you can merge and rebase in Git:

  • To merge the master branch into a feature branch: $ git checkout <feature-branch-name> && git merge master
  • To rebase changes from the master branch onto a feature branch: $ git checkout <feature-branch-name> && git rebase master

Bonus: Resolving Merge Conflicts

Sometimes, merge conflicts may occur during merging or rebasing. Here’s how you can resolve merge conflicts in Git:

  1. Open the conflicting file in a text editor.
  2. Locate the conflict markers (<<<<<<<, =======, and >>>>>>>).
  3. Edit the file to resolve the conflict, removing the conflict markers.
  4. Save the file.
  5. Stage the resolved file with $ git add <file-name>.
  6. Commit the changes with $ git commit -m "Resolved merge conflict".

Conclusion

This comprehensive Git Cheat Sheet is designed to help technical testers navigate Git commands with ease. By mastering these basic commands, you’ll improve your workflow, making collaboration more efficient and effective.

As you continue to develop your Git skills, consider exploring more advanced features and best practices, such as using Git hooks, configuring Git aliases, and working with submodules. Armed with this knowledge, you’ll be well on your way to becoming a Git expert in your field.

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

No responses yet

Write a response