The Git Workflow: Working Directory
The Git Workflow: Working Directory
Repository
The repository is the component that tracks the changes to the files in your project.
It contains all the commits (a snapshot of the files at a specific point) you create.
Working directory
The working directory contains the files currently being worked on.
Staging
The staging, is where commits are prepared. It allows users to view changes made to
the files in the project. When there is a change to a file in staging, it is marked as
modified and the user is able to see the diff (The modifications made to the files).
Git States
Modified
Staged
Commited
When a file is modified, the change can only be found in the working tree. Then, user
adds the changes to the staging to be able to commit them later on. The final step is
to commit these changes and this allow us to keep a snapshot of our work that we
can revisit later.
Before we can use Git on a working directory, we need to configure it properly. Here
are the commands for Git configuration:
# Shows current values for all global configuration parameters
git config --list --global
# Always sets the upstream branch of the current branch as the branch
# to be pushed to when no refspec is given
git config --global push.default tracking
Initializing Git is the next step after configuring it with the user name, email etc. that
we intend to use.
# Initializes a git repository in the current working directory
git init
# Tells Git to start tracking a file or add its current state to the index.
git add filename
# Modifies the last commit including both new modifications and given message.
git commit --amend -m "message"
# Turns the head of a branch into a commit in the currently checked out branch and merge it
git merge --squash mybranch
Diffing
# Shows the difference between two branches.
git diff branch1..branch2
Resetting