DEV Community

Cover image for Day-9: Unlock the Power of Git: Common Commands and Examples Explained
silambarasan rajendran
silambarasan rajendran

Posted on

4

Day-9: Unlock the Power of Git: Common Commands and Examples Explained

What is GIT?
Git is a free, open-source, and distributed version control system (DVCS) used to track changes in code, allowing developers to collaborate efficiently and manage project history.

Who created Git, and when?
Git was created by Linus Torvalds in 2005 to manage the Linux kernel's source code.

Here are some popular Git providers:

  1. GitHub
  2. GitLab
  3. Bitbucket

Install and validate the git in Linux Machine:
sudo apt install git -y
git --version

Git Workflow: Local → Staging → Remote

Here's a brief explanation of each stage in the Local - Staging - Remote flow:

Local:
This is your working directory on your computer, where you make changes to files (e.g., editing code, adding new files).

Staging:
Once you've made changes, you use git add to move them to the staging area. This is like a holding area where you prepare the changes before committing them to your local repository.

Remote:
After committing the changes locally with git commit, you can then push those changes to a remote repository (like GitHub, GitLab, or Bitbucket) using git push. This syncs your local commits with the remote repository so others can see and collaborate on the changes.
Enter fullscreen mode Exit fullscreen mode

Here’s a one-line explanation for each Git command, along with an example:

1. git init
Initializes a new Git repository in the current directory.
Example: git init – Creates a new .git folder in the directory to start tracking.

2. git clone
Clones an existing Git repository from a remote server to your local machine.
Example: git clone https://gitlab.com/ojm_b15/morning_java.git – Clones the repository from GitLab to your local system.

3. git config
Configures Git settings like user information and preferences.
Example: git config --global user.email "your.email@example.com" – Sets your email globally in Git.

4. git add
Stages changes (files) for the next commit.
Example: git add . – Stages all modified files in the current directory for commit.

5. git commit
Commits the staged changes with a message.
Example: git commit -m "Initial commit" – Commits the changes with the message "Initial commit."

6. git push
Pushes committed changes from your local repository to a remote repository.
Example: git push origin main – Pushes changes to the main branch of the remote repository.

7. git pull
Fetches and merges changes from the remote repository into your local repository.
Example: git pull origin main – Pulls the latest changes from the main branch of the remote repository.

8. git config --global user.email
Sets the global email address used for commits.
Example: git config --global user.email "fjgftfrfhjyjuj@gmail.com" – Configures the email for Git commits.

9. git config --global user.name
Sets the global username used for commits.
Example: git config --global user.name "e00049" – Configures the username for Git commits.

10. git config pull.rebase false 
This command sets Git to use a merge strategy (instead of rebase) when pulling changes from a remote repository. It ensures that the commit history remains a true reflection of the sequence of changes.
Example: git config pull.rebase false – Configures Git to merge changes      when pulling instead of rebasing.
Enter fullscreen mode Exit fullscreen mode

Note: The document formatting and structure were assisted by ChatGPT.

------------------- End of the Blog -------------------------------

Heroku

Deliver your unique apps, your own way.

Heroku tackles the toil — patching and upgrading, 24/7 ops and security, build systems, failovers, and more. Stay focused on building great data-driven applications.

Learn More

Top comments (0)

Image of PulumiUP 2025

Let's talk about the current state of cloud and IaC, platform engineering, and security.

Dive into the stories and experiences of innovators and experts, from Startup Founders to Industry Leaders at PulumiUP 2025.

Register Now

👋 Kindness is contagious

Explore a trove of insights in this engaging article, celebrated within our welcoming DEV Community. Developers from every background are invited to join and enhance our shared wisdom.

A genuine "thank you" can truly uplift someone’s day. Feel free to express your gratitude in the comments below!

On DEV, our collective exchange of knowledge lightens the road ahead and strengthens our community bonds. Found something valuable here? A small thank you to the author can make a big difference.

Okay