Git is a version control system. Version control, also known as source control, is the practice of tracking and managing changes to software code. Version control systems are software tools that help software teams manage changes to source code over time.
Git is used for:
- Tracking code changes
- Tracking who made changes
- Coding collaboration
Setting up a new Repository
A Git repository is a folder that Git tracks for changes.
The repository stores all your project's history and versions.
Add files to the folder.
The following describes how to set up a new repository:
Git Init
Initializes git
user@localhost $ git init
This creates a hidden folder called .git inside your project. This is where Git stores all the information it needs to track your files and history.
To see which files are in your project folder, use the ls command:
user@localhost $ ls
To Check if Git is tracking your new files:
user@localhost $ git status
The files here could either be tracked or untracked:-
- Untracked Files
Files you've created or copied into the folder, but haven't told Git to watch.
- Tracked Files
Files that Git is watching for changes.
To make a file tracked, you need to add it to the staging area.
Git Staging
Tells Git exactly which files you want to include in your next commit.
user@localhost $ git add .
Common Commands
git add .
Stages all new, modified, and deleted files in the current directory and its subdirectories.
git add <file>
Stages a specific file.
git add -A (or --all)
Stages all changes across the entire repository, regardless of your current folder location.
git add -u
Stages modifications and deletions of already-tracked files, ignoring completely new (untracked) files.
git add *.txt
Stages all files matching a specific pattern (e.g., all text files).
Git Commit
A commit is like a save point in your project.
It records a snapshot of your files at a certain time, with a message describing what changed.
user@localhost $ git commit -m " Describe your changes"
Pushing Changes
After you commit, your changes are only in your local repository.
Pushing sends your commits to a remote repository like GitHub.
user@localhost $ git push
Over 70% of developers use Git! Git does not store a separate copy of every file in every commit, but keeps track of changes made in each commit! For best use case, commit often and write clear commit messages.
Top comments (0)