Git

Last Updated: 7/13/2023

Git Workflow

  • Every day, as part of working on various tasks, we modify one or more files. When our project reaches a state we want to record, we commit those changes into our repository. Creating a commit is like taking a snapshot of our project.
  • Now in git, we have a special area or a special intermediate step that doesn't exist in most other version control systems. It's called the Staging area, or the index, is essentially what we're proposing for the next commit or the next snapshot.
  • So when we're done making changes, we add the modify files to the staging area or index git add file
  • In staging we review our changes, and if everything is good, then we'll make a commit. The proposed snapshot will get permanently stored in our repository. git commit -m "Initial commit"
  • So the staging area allows us to review our work before recording a snapshot. If some of the changes shouldn't be recorded as part of the next snapshot, we can unstaged them and commit them as part of another snapshot. That's the basic Git workflow.
  • Now a common misconception about Git is that once we commit the changes, the staging area becomes empty, this is not correct. So what we currently have in the staging area is the same snapshot that we stored in the repository.
  • Staging area is actually very similar to a staging environment we use when releasing software to production. It's either a reflection of what we currently have in production, or the next version that's going to go in production.
  • Each commit contains a unique identifier that gets generated by Git. It's like a revision number. Each commit also contain information about what was changed, by who, when, as well as a complete snapshot of our project at the time it was created. - So unlike many other version control systems, git doesn't store the deltas or what was changed. It stores the full content
  • With this, Git can quickly restore the project to an earlier snapshot without having to compute the changes.
  • Git is very efficient in data storage . it compresses file contents, and doesn't store duplicate content.
  • Each commit contains a complete snapshot of our project and this allows us to quickly get back to the previous state.