2. Installing and First-Time Setup
Before your first commit, configure identity and defaults:
•git config --global user.name "Your Name"
•git config --global user.email "
[email protected]"
•git config --global init.defaultBranch main
•Optional editor:git config --global core.editor "code --wait"
•Global ignore file: create ~/.gitignore_global and setgit config --global
core.excludesfile ~/.gitignore_global
Cloning and initializing:
•New project:git initthen add files → stage → commit.
•Existing project:git clone <url>.
Help on any topic:git help <command> orgit <command> --help.
3. Recording Changes Effectively
Great commits tell a story your teammates can follow. Aim for small, focused commits with
meaningful messages.
Workflow:
1)Edit files →git statusto see what changed
2)Review diffs →git diff(unstaged),git add -pfor interactive staging
3)Commit →git commit -m "Summarize the change"
Message style:
•Subject line in imperative mood, ≤ 72 chars
•Body: what changed, why it was needed, any side-effects or follow-ups
Common tools:
•Undo staged changes:git restore --staged <path>
•Restore a file from HEAD:git restore <path>
•Rename/move: git mv old new
4. Branching Basics
Branches are named pointers to commits. They allow parallel lines of development.
•Create:git branch feature/login orgit switch -c feature/login
•Move (checkout):git switch feature/login (preferred) orgit checkout feature/login
•List:git branch --show-current andgit branch --all
•Tag stable points:git tag v1.0.0
3