Git is an essential distributed version control system widely used in software development for tracking and managing changes in source code.
It facilitates collaboration among multiple developers, enabling efficient workflows through features like branching, merging, and remote repositories.
Mastering basic Git operations is essential for managing your projects effectively, keeping track of changes, and coordinating updates across teams.
The staging area (index) is where Git collects changes before committing. The git add command moves file changes from the working directory to the staging area.
1. Stage a specific file:
git add filename2. Stage all changed files recursively:
git add .3. You can stage newly created, modified, or deleted files.
Staging lets you prepare a meaningful group of changes for your next commit.
Committing Changes (git commit)
Once changes are staged, commit them to your local repository with a descriptive message.
1. Commit with a message:
git commit -m "Add feature X"2. Commit and open your configured editor to type a message:
git commit3. Each commit records a snapshot of your project’s state and metadata like author and timestamp.
The git status command provides information on the current state of your working directory and staging area:
 - visual selection-Picsart-CropImage.png)
Example output:
On branch main
Changes to be committed:
modified: file1.txt
Changes not staged for commit:
modified: file2.txt
Untracked files:
file3.txtViewing Commit History (git log)
git log shows the chronological list of commits in the current branch.
Common options include:
git log --oneline – brief one-line summaries.
git log -p – shows patch/diff for each commit.
git log --graph – visualizes branch structure.
Understanding the log helps explore project history and collaborate effectively.
Pushing Changes to Remote Repository (git push)
To share commits with others or back up your work, push changes to a remote repository.
1. First, add the remote repository if not done yet:
git remote add origin <remote-url>2. Push changes to the remote branch (usually main or master):
git push origin main3. Ensure you have permission and network access to the remote.
Pushing makes your changes available in collaborative platforms like GitHub, GitLab, or Bitbucket.
Pulling Changes from Remote (git pull)
Synchronize your local repository with remote updates:
git pull origin mainThis fetches the latest changes and merges them locally, keeping your branch up-to-date.
Undoing Changes
git reset HEAD filenamegit checkout -- filenameThese help correct mistakes or abort unwanted changes before committing.