git merge
is used to combine branches1. Keep master’s changes
2. Keep the branch’s changes
3. Combine both
git merge --abort
Abort a merge in progress.git reset
can also unstage changes.apply
and pop
use the most recent stash.A repository (or repo) is just a project folder tracked by Git.
It contains:
- Code
- Documentation
- History of changes
Repositories can live locally (on your machine) or remotely (e.g., GitHub).
Lists all branches in the repo.
In a fresh repo without any commits, no branch is shown, because Git requires at least one commit to recognize a branch.
After your first commit, you’ll see the master
(or main
) branch.
Git Stages
When you create a new branch, it starts from the HEAD of the current branch.
Used to check details, history, and metadata of commits.
Rebasing moves the base of a branch to a different commit.
- With rebase, merges can be fast-forward (no extra merge commits).
eg to update feature branch with the latest main
:
Stash = temporary storage for your changes.
git status
git config --global --list
git config --global user.email "your_email@example.com"
git config --global user.name "your_name"
git init
git branch
git add .
git commit -m "initial commit"
git log --oneline
git reflog
git switch master
git switch -c feature_branch
git checkout -b feature_branch
git checkout feature
git rebase main
git reset --hard HEAD~1
git reset --hard <commit_id>
git cherry-pick <commit_id>
git cherry-pick <commit id1> <id2> <id3>.
git stash push -m "paused my development"
git stash list
git stash apply
git stash pop
git branch -m main # Rename current branch to main
git pull origin main # Fetch and merge latest changes from remote main
git pull origin main --allow-unrelated-histories # Pull even if histories are unrelated
git push origin main # Push local main branch to remote
git diff # Show changes between working directory and staging area
git reset
git diff # compares working directory and staging area.