DEV Community

Cover image for πŸ› οΈ Essential Git Commands for Professional Employers 🌟
Sachin Gadekar
Sachin Gadekar

Posted on

3

πŸ› οΈ Essential Git Commands for Professional Employers 🌟

Hey Devs! πŸš€ Level up your Git game with these essential commands. Whether you’re starting a new project, managing branches, or pushing changes, these commands have got you covered. Let’s dive in! πŸŠβ€β™‚οΈ


1. git init - Initialize a New Git Repository πŸ—ƒοΈ

The git init command creates a new Git repository. Start your project the right way!

git init
Enter fullscreen mode Exit fullscreen mode

2. git remote add origin - Connect to a Remote Repository 🌍

Add a remote repository to your local Git setup with git remote add origin.

git remote add origin <remote_repository_URL>
Enter fullscreen mode Exit fullscreen mode

3. git add . - Stage Changes for Commit πŸ“¦

Use git add . to add all changes in the working directory to the staging area.

git add .
Enter fullscreen mode Exit fullscreen mode

4. git commit -m 'message' - Commit Your Changes πŸ’Ύ

Capture a snapshot of your project's staged changes with git commit.

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

5. git push - Push Changes to Remote πŸš€

Send your local changes to a remote repository with git push.

git push
Enter fullscreen mode Exit fullscreen mode

6. git push origin <branch_name> - Push a Branch πŸ“€

Push a local branch to a remote repository with git push origin.

git push origin <branch_name>
Enter fullscreen mode Exit fullscreen mode

7. VIM Editor Edit πŸ“

Edit a file in VIM editor by pressing Escape and then I.


8. VIM Editor Save and Exit πŸ’Ύ

Save and exit in VIM editor by pressing Escape and entering :wq.


9. git log - View Commit History πŸ“œ

Display the committed snapshots with git log.

git log
Enter fullscreen mode Exit fullscreen mode

--

10. git branch - List Branches 🌿

See all branches in your repository with git branch.

git branch
Enter fullscreen mode Exit fullscreen mode

11. git branch <branch_name> - Create a New Branch 🌱

Create a new branch in your local repository with git branch.

git branch <branch_name>
Enter fullscreen mode Exit fullscreen mode

12. git push origin <branch_name> - Push a Created Branch 🌍

Push a newly created branch from local to the remote repository with git push origin.

git push origin <branch_name>
Enter fullscreen mode Exit fullscreen mode

13. git checkout -b <branch_name> - Create and Switch Branch πŸ”„

Create a new branch and switch to it with git checkout -b.

git checkout -b <branch_name>
Enter fullscreen mode Exit fullscreen mode

14. git checkout <branch_name> - Switch Branches 🌟

Switch to a specified branch with git checkout.

git checkout <branch_name>
Enter fullscreen mode Exit fullscreen mode

15. git push origin --delete <branch_name> - Delete a Remote Branch πŸ—‘οΈ

Delete a branch from the remote repository with git push origin --delete.

git push origin --delete <branch_name>
Enter fullscreen mode Exit fullscreen mode

16. git branch --delete <branch_name> - Delete a Local Branch 🧹

Delete a branch from your local repository with git branch --delete.

git branch --delete <branch_name>
Enter fullscreen mode Exit fullscreen mode

17. git restore --staged <file_name> - Unstage a File πŸ”„

Unstage a file with git restore --staged.

git restore --staged <file_name>
Enter fullscreen mode Exit fullscreen mode

18. git reset - Unstage All Files πŸ—ƒοΈ

Unstage all files with git reset.

git reset
Enter fullscreen mode Exit fullscreen mode

--

19. git reset --hard - Unstage and Reset Changes 🚨

Unstage and reset all changes from the working directory with git reset --hard.

git reset --hard
Enter fullscreen mode Exit fullscreen mode

20. git rm -f <file_name> - Remove a File ❌

Remove a file from the staging area and working directory with git rm -f.

git rm -f <file_name>
Enter fullscreen mode Exit fullscreen mode

--

21. git rm --cached <file_name> - Remove from Staging Area 🚫

Remove a file from the staging area only with git rm --cached.

git rm --cached <file_name>
Enter fullscreen mode Exit fullscreen mode

--

22. git push --force - Force Push πŸš€

Forcefully push changes to a specific branch, ignoring conflicts with git push --force.

git push --force
Enter fullscreen mode Exit fullscreen mode

23. git push origin --delete <branch_name> - Delete Remote Branch πŸ—‘οΈ

Delete a branch from the remote repository with git push origin --delete.

git push origin --delete <branch_name>
Enter fullscreen mode Exit fullscreen mode

24. git branch -D <branch_name> - Force Delete Local Branch ⚑

Forcefully delete a branch from the local repository with git branch -D.

git branch -D <branch_name>
Enter fullscreen mode Exit fullscreen mode

Buy Me A Coffee

Sentry image

See why 4M developers consider Sentry, β€œnot bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

Top comments (1)

Collapse
 
dipakahirav profile image
Dipak Ahirav β€’

nice one and useful

SurveyJS custom survey software

JavaScript UI Libraries for Surveys and Forms

SurveyJS lets you build a JSON-based form management system that integrates with any backend, giving you full control over your data and no user limits. Includes support for custom question types, skip logic, integrated CCS editor, PDF export, real-time analytics & more.

Learn more

πŸ‘‹ Kindness is contagious

Please leave a ❀️ or a friendly comment on this post if you found it helpful!

Okay