Git records changes to files and helps teams work safely on the same project. This guide covers the commands and flows used most often in daily development and test automation work.

Before you start

Configure your identity once. Git adds it to your commits.

git config --global user.name "Your Name" git config --global user.email "you@example.com" # Check the configuration git config --list

Get a project

# Copy an existing remote repository git clone https://github.com/team/project.git cd project # Or start Git in an existing local folder git init

Everyday commands

CommandUse
git statusShow changed, staged and untracked files.
git diffShow unstaged changes.
git diff --stagedShow changes ready to commit.
git add file.tsStage one file.
git add .Stage all current changes. Review them first.
git commit -m "Add login test"Create a commit from staged changes.
git log --oneline --graph --allShow compact branch history.
git fetch originDownload remote history without changing your files.
git pullFetch and integrate changes into the current branch.
git pushSend committed changes to the remote repository.
git branchList local branches.
git switch branch-nameMove to another branch.
git switch -c feature/login-testsCreate a branch and switch to it.
git stashTemporarily store uncommitted tracked changes.
git stash popRestore the latest stash and remove it from the stash list.
Good habit: run git status before and after an important command. It tells you where you are and what Git expects next.

Feature branch workflow

Example: start from development, create a feature branch, finish the work and merge it back.

1. Start from an updated development branch

git switch development git pull origin development

2. Create the feature branch

git switch -c feature/add-login-tests

3. Make and review your changes

git status git diff git add tests/login.spec.ts git diff --staged git commit -m "Add login test coverage"

4. Push the branch

git push -u origin feature/add-login-tests

The -u option links the local branch to the remote branch. Later, git push is enough.

5. Merge through a pull or merge request

  1. Open a pull request from feature/add-login-tests into development.
  2. Wait for review and CI checks.
  3. Resolve comments or conflicts.
  4. Merge using the method agreed by the team.
  5. Delete the feature branch when it is no longer needed.

Alternative: merge locally

git switch development git pull origin development git merge feature/add-login-tests git push origin development # Delete the local feature branch after a successful merge git branch -d feature/add-login-tests
Team rule first: many projects protect development and require a pull request. Do not push or merge directly unless the project allows it.

Keep your branch up to date

If development changed while you were working, update your feature branch before opening the pull request.

Approach A: merge development into the feature branch

git switch development git pull origin development git switch feature/add-login-tests git merge development

This keeps the existing commits and may create a merge commit.

Approach B: rebase the feature branch

git fetch origin git switch feature/add-login-tests git rebase origin/development

This reapplies your branch commits on top of the latest development. It creates a cleaner linear history.

Be careful with rebase: avoid rebasing commits other people already use. If you rebased a branch already pushed by you, use git push --force-with-lease, not plain --force.

Resolve a merge conflict

  1. Run git status to see conflicted files.
  2. Open each file and find the conflict markers.
  3. Choose or combine the correct changes.
  4. Remove the markers.
  5. Run the relevant tests.
  6. Stage the resolved files.
  7. Complete the merge or rebase.
git status git add path/to/resolved-file.ts # Complete a merge git commit # Or continue a rebase git rebase --continue

To stop and return to the previous state:

git merge --abort # or git rebase --abort

Undo changes safely

SituationCommand
Discard unstaged changes in one filegit restore file.ts
Remove a file from staging but keep its changesgit restore --staged file.ts
Change the latest commit messagegit commit --amend -m "New message"
Create a new commit that reverses an old commitgit revert commit-id
Temporarily save tracked workgit stash push -m "Work in progress"
Show saved stashesgit stash list
Safest shared-history option: use git revert for a commit already pushed and used by others. Avoid destructive reset commands unless you fully understand what will be lost.

Useful approaches

Small branches

Keep each branch focused on one change. It is easier to review, test and merge.

Clear branch names

Use patterns such as feature/, bugfix/, test/ or the Jira ticket ID.

Focused commits

Commit one logical change at a time with a short action-based message.

Review before commit

Use git diff and git diff --staged to avoid committing debug code or secrets.

Pull requests

Use review and automated checks before merging into a shared branch.

Ignore generated files

Add dependencies, reports, test results and local secrets to .gitignore.

Typical test automation .gitignore

node_modules/ playwright-report/ test-results/ .env *.log

Useful links