DEV Community

Cover image for Git One stop
Purna Pattela
Purna Pattela

Posted on

Git One stop

Here are some of the commonly used git commands by every developer :)

πŸ“Œ Table of Contents

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
Enter fullscreen mode Exit fullscreen mode

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 .
Enter fullscreen mode Exit fullscreen mode

Track specific files or folders

To individually add files or folders for tracking:

git add file_or_folder_name
Enter fullscreen mode Exit fullscreen mode

Checking the status

To see the current state of the working directory and staging area:

git status
Enter fullscreen mode Exit fullscreen mode

Commit the code

After staging the changes, commit them with a message:

git commit -m "Your descriptive commit message"
Enter fullscreen mode Exit fullscreen mode

How to check logs

To view the commit history:

git log
Enter fullscreen mode Exit fullscreen mode

You can use options like --oneline for a summarized view:

git log --oneline
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

To see the list of remotes:

git remote -v
Enter fullscreen mode Exit fullscreen mode
  • 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
Enter fullscreen mode Exit fullscreen mode

Replace main with your branch name if different.

Top comments (0)