Mastering basic Git commands

Learn the basic git commands needed for your daily life.

Image from Unsplash(Yancy Min)
  1. Create a new local repository.
git init

2. Clone a remote branch into your machine.

git clone “repository url”

3. List all local branches.

git branch

4. List remote and local branches.

git branch -a

5. Switch to an existing branch.

git checkout Branch_Name

6. Create a local branch and switch to it.

git checkout -b Branch_name

7. Push branch to remote.

git push origin Branch_Name

8. Rename your local branch.

git branch -m New_Name

Renaming a branch you are not currently using.

git branch -m Old_Name New_Name

9. Delete the Old_name remote branch and push the New_name local branch.

git push origin :Old_Name New_Name

10. To Reset the upstream branch for the New_name local branch. This means all your changes which you are uploading need to be pointed to the branch with new name.

git push origin -u New_Name

11. Delete a local branch.

git branch -d Branch_Name

12. Delete a remote branch.

git push origin :Branch_Name

13. Delete all untracked files.

git clean -f

14. Delete all untracked files and directories.

git clean -df

15. Undo local modifications to all files.

git checkout -- .

16. Undo local modifications to a specific file.

git checkout File_Name

17. Display all local file changes in the working branch.

git diff

18. Display changes made to a file in the working branch.

git diff File_Name

19. Display who changed the file and when they changed the file.

git blame File_Name

20. Display commit history in a single line

git log --oneline

21. List all tags

git tag

22. Creating a new tag

git tag -a Tag_Name -m 'Message'

23. Push all tags to remote

git push --tags

24. Reset all your changes in a local branch

git reset --hard

25. Pull changes from the remote specific branch and merge them to the local checked-out branch.

git pull origin Branch_Name

26. Pull changes from the locally stored branch and merge that to the local checked-out branch.

git pull origin/Branch_Name

Thanks 😊 🙏 for Reading 📖.

Follow me JavaScript Jeep🚙💨 .

Please make a donation here. 80% of your donation is donated to someone needs food 🥘. Thanks in advance.

Leave a comment

Design a site like this with WordPress.com
Get started