Here are some of the commonly used git commands by every developer :)
π Table of Contents
- Why should we use Git ?
- Terminology in git
- Initialize a git repository
- Staging the code
- Checking the status
- Commit the code
- How to check logs
- What is Git remote
- Pushing the code
Why should we use Git ?
Git is a Version Control System (VCS) used to track changes in source code and efficiently manage multiple versions of a project.
Here is a blog with in-depth comparison with VCS and without VCS
Terminology in git
| Term | Meaning |
|---|---|
| Repository (Repo) | A storage location for a project that contains the source code and its version history |
| Staging Area | An intermediate area where changes are placed before committing |
| Commit | A snapshot of changes made to the repository with a descriptive message |
| Branch | A separate line of development used to add new features or fixes |
| Remote | A repository hosted on a server (GitHub, GitLab, etc.) |
| Clone | Creating a local copy of a remote repository |
| Main / Master | The default branch of the repository |
| Merge | Combining changes from different branches |
| Pull | Fetching and merging the latest changes from the remote repository |
| Conflict | Occurs when Git cannot automatically merge changes |
| HEAD | A pointer to the current branch or commit |
| Stash | Temporarily stores changes without committing them |
Initialize a git repository
Initialize a git repository means adding git feature to the codebase. It creates the .git folder when we run the command. The working of git starts from here.
git init
Staging the code
Staging is the area where changes are added before committing, telling Git which files to track for the next commit.
Track all changes
This tracks the complete folder where Git is initialized:
git add .
Track specific files or folders
To individually add files or folders for tracking:
git add file_or_folder_name
Checking the status
To see the current state of the working directory and staging area:
git status
Commit the code
After staging the changes, commit them with a message:
git commit -m "Your descriptive commit message"
How to check logs
To view the commit history:
git log
You can use options like --oneline for a summarized view:
git log --oneline
What is Git remote
A remote is a version of your repository hosted on a server like GitHub or GitLab.
To add a remote repository:
git remote add origin https://github.com/username/repo.git
To see the list of remotes:
git remote -v
- we can also have the read stream and write stream as different repos
Pushing the code
To send your local commits to the remote repository:
git push origin main
Replace main with your branch name if different.
Top comments (0)