In any collaborative coding project, keeping track of changes, updates, and collaboration is crucial. Git, a distributed version control system, provides a structured workflow to manage this. Here, we'll break down the essential components and commands of the Git workflow.
Local Repo
"Local" refers to the version of the repository that is on your personal computer. This local repository is where you do your work, make changes, and test features.
Working Directory The working directory is where your current project files reside. This is your main workspace where you create, edit, and delete files.
Add: Once you've made changes, you use the
add
command to stage these changes. This prepares the changes to be committed to the repository.
Staging Area The staging area is a temporary storage for changes that are meant to be included in the next commit. Think of it as a preview of your next commit snapshot.
Commit: The
commit
command takes everything from the staging area and stores it in the local repository. Each commit is a snapshot of your project at a given point in time.
Local Repository Your local repository is where all your project’s commits are stored. This is your personal copy of the project history, which you can manipulate and manage independently of others.
Commit: As mentioned,
commit
saves changes to the local repository.Fetch: The
fetch
command allows you to see what others have been working on by downloading objects and refs from another repository, without merging these changes into your work.Pull: The
pull
command combinesfetch
andmerge
, fetching changes from the remote repository and merging them into your local repository in one step.
Remote Repo
"Remote" refers to a version of your repository that is hosted on a server and is typically used to share your work with others.
Remote Repository The remote repository is a version of your project that is hosted on a server (e.g., GitHub, GitLab). It allows multiple collaborators to push their changes and keep everything in sync.
Push: The
push
command uploads your local repository changes to the remote repository, making your commits available to others.Fetch: As mentioned,
fetch
retrieves changes from the remote repository to your local repository, allowing you to see updates without integrating them immediately.
The Animation
These are the essential Git commands shown at the top of the diagram:
Add: Adds changes in the working directory to the staging area.
Commit: Saves the changes from the staging area to the local repository.
Push: Uploads local repository changes to the remote repository.
Fetch: Downloads objects and refs from another repository.
Pull: Fetches and integrates changes from the remote repository into the local repository.
Clone: Creates a copy of an existing remote repository.
Checkout: Switches branches or restores working tree files.
Rebase: Reapplies commits on top of another base tip.
Log: Shows the commit logs.
Status: Displays the state of the working directory and staging area.