Useful Git Commands You Need To Know

Useful Git Commands You Need To Know

ยท

3 min read

๐Ÿ‘‰ Original Blog Post : Link

Git is the most commonly used version control system. Git tracks the changes you make to files, so you have a record of what has been done, and you can revert to specific versions should you ever need to. Git also makes collaboration easier, allowing changes by multiple people to all be merged into one source.

So regardless of whether you write code that only you will see, or work as part of a team, Git will be useful for you.

Commands List

  1. git init -> Initializes git in any folder/repository (Needs only if you are not cloning a repository)

  2. git clone https://github.com/<your-user-name>/<repo-name> -> Clones the repository in your local system.

  3. git status -> Shows the current status of the repository.

  4. git add <file-name> -> Adds specific file to staging area

  5. git diff / git whatchanged -> Gives the recent changes in the repository

  6. git add . -> Adds all changed files to staging area

  7. git commit -m "<your-message>" -> Gives a message to your current files and takes their snapshot to commit history

  8. git log -> Shows the commit history

  9. git revert <commit-token> -> Discards the specific commit (Deletes the committed files but keeps a trace in history)

  10. git reset --soft HEAD~<no-of-commits-to-revert> -> Undo's the commit and brings the changes back in the staging area

  11. git restore --staged <file> -> Brings back the specific file in the changes made section which is added to the staging area.

  12. git remote -v -> Shows all the remote connection

  13. git remote add origin https://github.com/<your-user-name>/<repo-name> -> adds your forked branch as the origin (No need to do if the repo is cloned)

  14. git remote add upstream https://github.com/<parent-user-name>/<repo-name> -> Adds parent repository as upstream.

  15. git pull origin -> fetches the changes made in origin to your local system

  16. git pull upstream -> fetches the changes made in origin to your local system

  17. git branch <branch-name> -> Creates a branch with branch-name

  18. git checkout <branch-name> -> This now allows you to make changes in the specified branch

  19. git checkout -b <branch-name> -> This is combination of git branch and git checkout

  20. git merge <branch-name> -> merges its children branch-name into its parent branch.

  21. git branch -d <branch-name> -> Deletes the specified branch. And if the changes in the branch-name are not merged in the parent branch then the changes are deleted.

  22. git push origin <branch-name> -> Pushes the recent commits to the new branch

Thank You for reading till here. Meanwhile you can check out my other blog posts and visit my Github.

I am currently working on Stone CSS ( Github ) as well.

Did you find this article valuable?

Support Devarshi Shimpi by becoming a sponsor. Any amount is appreciated!

ย