20 Git command mà mọi lập trình viên cần biết

Trong bài viết này, tôi sẽ giới thiệu nhanh một số các command trong Git mà tôi thường sử dụng.

1. git init

Command này sử dụng để khởi tạo một dự án

2. git remote add origin

Ví dụ

git remote add origin https://github.com/f7deat/git-command

Command này sử dụng để kết nối tới một remote repository

3. git remote

Command này sử dụng để xem project đang kết nói tới remote repositories nào

4. git status

Command này sử dụng để xem trạng thái của một file ở local

5. git add

ví dụ

git add index.html
git add index.html style.css main.js

Command này sẽ stage các file được modified hoặc untracked

git add -a

Statge toàn bộ unstaged file

6. git reset

Unstage toàn bộ file

7. git commit

Commit toàn bộ file đã staged

git commit - m "message"

ví dụ

git commit -m "this is example commit message"

commit toàn bộ staged file và ghi chú tin nhắn ở commit history

git commit --amend

Chỉnh sửa commit gần nhất

8. git push -u origin

ví dụ

git push -u origin master

Push toàn bộ file đã được commit tói remote repository

git push

Push toàn bộ file tới remote repository

9. git fetch

update phiên bản mới nhất của local repository

10. git pull

Update local repository tới version mới nhất từ remote repository

11. git rm -r --cached

ví dụ

git rm -r --cached config.js

Xóa một file từ remote repository

12. git branch

Xem branch đang active

git branch -a

Xem toàn bộ branch tại local và remote repository

git branch -r

Xem toàn bộ branch tại local repository

13. git checkout --track origin/

ví dụ

git checkout --track origin/develop

Đổi branch

14. git checkout

ví dụ

git checkout master

Đổi branch

15. git merge

Merge 2 branch với nhau

ví dụ

git merge develop

16. git merge --abort

Abort merge code

18. git reset --hard HEAD

Xóa toàn bộ thay đổi của bạn tại local repository

19. git clean -f

Xóa toàn bộ untracked file tại local repository

20. git clean -d

Xóa toàn bộ folder tại local repository

21. git bisect

xem toàn bộ file là bug trong code

22. git reset HEAD^

Xóa các thay đổi của bạn về commit mới nhất

23. git diff

Xem sự thay đổi của file

24. git rebase

Chức năng cơ bản giống git merge nhưng sẽ khiến history của bạn đẹp và dễ trace log hơn

25. git stash

Đưa các thay đổi của bạn vào một vùng nhớ đặc biệt

26. git reflog

Rất quan trọng nếu bạn làm điều gì đó sai sai với commit của mình

27. git cherry-pick

Chọn ra các commit cần, ko phải toàn bộ từ branch của bạn sang branch muốn merge

ví dụ

git cherry-pick <commit-hash>
Git
343 | 7/27/2022 9:50:59 AM
Bình luận
Để lại bình luận Đăng nhập / Đăng ký
No data
Không có dữ liệu