DEV Community

khaled-17
khaled-17

Posted on

2

Top Git Commands Every Developer Should Know

Initialize a Repository:

   git init
Enter fullscreen mode Exit fullscreen mode

Clone a Repository:

   git clone <repository_url>
Enter fullscreen mode Exit fullscreen mode

Check Repository Status:

   git status
Enter fullscreen mode Exit fullscreen mode

Stage Changes:

   git add <file_name>
Enter fullscreen mode Exit fullscreen mode

Commit Changes:

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

View Commit History:

   git log
Enter fullscreen mode Exit fullscreen mode

Create a New Branch:

   git branch <branch_name>
Enter fullscreen mode Exit fullscreen mode

Switch to a Branch:

   git checkout <branch_name>
Enter fullscreen mode Exit fullscreen mode

Merge Branches:

   git merge <branch_name>
Enter fullscreen mode Exit fullscreen mode

Pull Changes from a Remote Repository:

bash
git pull origin <branch_name>

Push Changes to a Remote Repository:

bash
git push origin <branch_name>

Check Differences between Branches:

bash
git diff <branch1> <branch2>

Discard Changes in Working Directory:

bash
git checkout -- <file_name>

Undo the Last Commit (Keep Changes):

bash
git reset --soft HEAD^

Undo the Last Commit (Discard Changes):

bash
git reset --hard HEAD^

Stash Changes:

bash
git stash

Apply Stashed Changes:

bash
git stash apply

Create a Tag:

bash
git tag -a <tag_name> -m "Your tag message"

Fetch Changes from a Remote Repository:

bash
git fetch origin

Remove Untracked Files:

bash
git clean -fd

Heroku

Build apps, not infrastructure.

Dealing with servers, hardware, and infrastructure can take up your valuable time. Discover the benefits of Heroku, the PaaS of choice for developers since 2007.

Visit Site

Top comments (0)

Billboard image

Create up to 10 Postgres Databases on Neon's free plan.

If you're starting a new project, Neon has got your databases covered. No credit cards. No trials. No getting in your way.

Try Neon for Free →