Reference article · Programming
Git: changes, commits, branches and remotes
Git records project history and supports development branches. GitHub and other platforms can host Git repositories, but Git also works locally without an account on those services.
Three distinct places
The working directory contains edited files. The staging area selects content for the next commit. A commit records a snapshot of staged content. Saving a file does not create a commit; making a commit does not automatically publish it.
First workflow in a practice folder
Install Git and configure a commit identity. In a new folder, create notas.txt first, then run these commands. Adding a specific file makes the selection easier to review.
git init git status git add notas.txt git diff --staged git commit -m "Add initial notes" git log --oneline
Review before recording
git diff shows unstaged tracked changes; git diff --staged shows staged content. git status also identifies new untracked files. Review content and filenames before committing; exclude passwords and .env files containing secrets.
Branches and conflicts
git switch -c creates and selects a branch. Integration can produce conflicts when Git cannot combine changes automatically. Resolve the content, verify the result and stage resolved files before completing integration.
git switch -c improve-documentation git status
Remotes: fetch, pull and push
A remote identifies another repository. fetch downloads history without integrating it into the current branch. pull retrieves changes and attempts integration according to configuration. push sends commits and requires a destination and permission. Check git remote -v and your branch before syncing.
Exercise
- Create two notes commits and compare their history messages.
- Edit a line and compare diff before and after add.
- Create a practice branch and check git branch --show-current.
References
Related articles
- Fundamentals: variables, conditions and loops
- Semantic HTML and page structure
- CSS: box model, Flexbox and Grid
- JavaScript: functions, parameters and scope
- JavaScript: arrays, objects and data transformations
- DOM and events: connect JavaScript to HTML
- Promises, async/await and fetch requests
- HTTP and web APIs: requests, responses and status codes
- JSON: format, parsing and data validation
- Node.js and npm: project scripts and dependencies
- Debugging and tests: finding and checking errors
- Colour formats: HEX, RGB and HSL
- UUID identifiers
- Random values in JavaScript
