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
| Command | Use |
|---|---|
git status | Show changed, staged and untracked files. |
git diff | Show unstaged changes. |
git diff --staged | Show changes ready to commit. |
git add file.ts | Stage 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 --all | Show compact branch history. |
git fetch origin | Download remote history without changing your files. |
git pull | Fetch and integrate changes into the current branch. |
git push | Send committed changes to the remote repository. |
git branch | List local branches. |
git switch branch-name | Move to another branch. |
git switch -c feature/login-tests | Create a branch and switch to it. |
git stash | Temporarily store uncommitted tracked changes. |
git stash pop | Restore the latest stash and remove it from the stash list. |
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
- Open a pull request from
feature/add-login-testsintodevelopment. - Wait for review and CI checks.
- Resolve comments or conflicts.
- Merge using the method agreed by the team.
- 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
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.
git push --force-with-lease, not plain --force.Resolve a merge conflict
- Run
git statusto see conflicted files. - Open each file and find the conflict markers.
- Choose or combine the correct changes.
- Remove the markers.
- Run the relevant tests.
- Stage the resolved files.
- 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
| Situation | Command |
|---|---|
| Discard unstaged changes in one file | git restore file.ts |
| Remove a file from staging but keep its changes | git restore --staged file.ts |
| Change the latest commit message | git commit --amend -m "New message" |
| Create a new commit that reverses an old commit | git revert commit-id |
| Temporarily save tracked work | git stash push -m "Work in progress" |
| Show saved stashes | git stash list |
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
Keep each branch focused on one change. It is easier to review, test and merge.
Use patterns such as feature/, bugfix/, test/ or the Jira ticket ID.
Commit one logical change at a time with a short action-based message.
Use git diff and git diff --staged to avoid committing debug code or secrets.
Use review and automated checks before merging into a shared branch.
Add dependencies, reports, test results and local secrets to .gitignore.
Typical test automation .gitignore
node_modules/
playwright-report/
test-results/
.env
*.log