Abílio Azevedo.

Git (Global Information Tracker) - Versioning

Cover Image for Git (Global Information Tracker) - Versioning
Abílio Azevedo
Abílio Azevedo

Git - A Distributed Version Control System

Git is a distributed version control system that was created by Linus Torvalds in 2005 for development of the Linux kernel. Git tracks changes made to a codebase over time and allows multiple developers to work on the same codebase simultaneously.

How Git Works

Git works by recording changes to a codebase as commits. Each commit captures a snapshot of the files and directories at a point in time. Git stores this information in a local database on the developer's machine. Developers can then push and pull commits to and from remote repositories to share changes and synchronize their local codebase with others.

Key Features of Git:

  • Distributed - Developers have a full copy of the Git repository and commits are stored locally. This allows work offline and without relying on a central server.

  • Branching and merging - Branches isolate work and changes can be merged between branches. This supports concurrent development.

  • Integrity - Git tracks checksums of file contents and directory structures to ensure integrity and prevent data corruption.

  • History tracking - Git tracks all changes in the history of a project, allowing revisiting any version.

Using Git

Some common Git commands and workflows include:

  • git clone - Clones/copies a remote repository to your local machine

  • git add - Stages file changes to be committed

  • git commit - Records changes in the local repository

  • git push - Pushes local commits to the remote repository

  • git pull - Pulls latest commits from remote repository

  • git branch - Manages branches to isolate work

  • git merge - Merges changes between branches

  • git log - Views commit history and changes

Recover Droped Stash

  • List the hash commits/stash that are in the cache
git fsck --no-reflog | awk '/dangling commit/ {print $3}'
  • Get commit/stash info to find the one you want to recover
git show da820072f5484b93c3a197212c7a32ba7748a519
  • Apply the found stash
git stash apply da820072f5484b93c3a197212c7a32ba7748a519

Remove a file from your branch's GIT commit history

git filter-repo --path .env --invert-paths

Cherry Picking

Cherry-picking in Git allows you to selectively apply commits from one branch into another. This can be useful when you only want to take certain commits from a feature branch and merge them into a release branch, for example.

git cherry-pick 368263d1eff5

Without commit it:

git cherry-pick -n 368263d1eff5

Git Providers like GitHub

Git repository hosting providers like GitHub offer collaboration features on top of Git version control. These include:

  • Issue tracking - Track feature requests and bugs

  • Pull requests - Allows reviewing changes before merging

  • Access control - Manage user permissions

  • Visualizations - Graphs to visualize project activity

  • Project hosting - Hosts project websites and documentation

Conclusion

So in summary, Git is a distributed version control system that offers superior source code management. It is complemented by Git providers like GitHub that add collaborative functions like pull requests and issue tracking. Together they provide a complete version control and project hosting solution.

References

Learning more about GIT: https://learngitbranching.js.org


More posts

Cover Image for CI/CD - Lint - Checks

CI/CD - Lint - Checks

Comprehensive guide to continuous integration and continuous delivery. Explains key concepts, tools like GitHub Actions and Drone, benefits of linting, integrating ESLint and Prettier, and using Git hooks for automation.

Abílio Azevedo
Abílio Azevedo
Cover Image for ReWork

ReWork

Unconventional, straight-to-the-point advice on how to run a business. Instead of focusing on fast growth, Rework encourages entrepreneurs to start small, stay agile, and focus on what's essential.

Abílio Azevedo
Abílio Azevedo

NewsLetter

I will send the content posted here. No Spam =)