Những lệnh git hay dùng trong thực tế

BBMCode đã đăng vào lúc 08:07:24 20/07/2024 | đọc khoảng 2 phút, có 280 từ

Dưới đây là một vài câu lệnh git hữu ích trong các trường hợp thực tế khi làm dự án

 

Config global thông tin user name và email

git config --global user.name "bbmcode"
git config --global user.email "bbmcode247@gmail.com"

 

Tạo mới repository

git clone https://github.com/bbmcode/tips.git
cd tips
touch README.md
git add README.md
git commit -m "add README"
git push -u origin master

 

init repository trong một folder có sẵn

cd existing_folder
git init
git remote add origin https://github.com/bbmcode/tips.git
git add .
git commit -m "Initial commit"
git push -u origin master

Push toàn bộ code local lên remote repository trong lần đầu tiên

git add .
git commit -m "Initial commit"
git remote add origin https://github.com/bbmcode/tips.git
git pull origin master --allow-unrelated-histories
git push -u origin master

 

Push toàn bộ sang repository mới (có sẵn)

cd existing_repo
git remote rename origin old-origin
git remote add origin https://github.com/bbmcode/tips.git
git push -u origin --all
git push -u origin --tags

 

Revert commit sau cùng

// revert locally
git reset --soft HEAD~1
// apply revert lên remote repository
git push -f origin local_branch_name:remote_branch_name

 

Setting để git không phân biệt tên file hoa hay thường

git config core.ignorecase false