Skip to content

Instantly share code, notes, and snippets.

@socmia
Created May 13, 2020 02:15
Show Gist options
  • Save socmia/72ce3c45f8a1fdb8c4421e80f0230c43 to your computer and use it in GitHub Desktop.
Save socmia/72ce3c45f8a1fdb8c4421e80f0230c43 to your computer and use it in GitHub Desktop.

Git global setup git config --global user.name "Tran Dang Doanh" git config --global user.email "dangdoanh.sp@gmail.com"

Create a new repository git clone ssh://git@192.168.0.135:30001/doanhtd/cnafis.git cd cnafis touch README.md git add README.md git commit -m "add README" git push -u origin master

Existing folder cd existing_folder git init git remote add origin ssh://git@192.168.0.135:30001/doanhtd/cnafis.git git add . git commit -m "Initial commit" git push -u origin master

Existing Git repository cd existing_repo git remote rename origin old-origin git remote add origin ssh://git@192.168.0.135:30001/doanhtd/cnafis.git git push -u origin --all git push -u origin --tags

git remote -v => origin link (fetch) origin link (push)

Lưu thay đổi, chuyển qua branh khác git stash git checkout correct-branch git stash pop

Xem thay đổi (chưa đc add) của những file hiện tại git diff Xem thay đổi (đã được add, chưa commit) git diff --cached git show --pretty="" --name-only d4f6c2c

  • Neu da checkout voi repo fork thi set lai url ve repo master git remote set-url origin git@github.com:USERNAME/REPOSITORY.git

  • Và cuối cùng add origin cho sub-project git remote add longlv sub-project-link

  • Check lại danh sách các remote git remote -v ==> origin super-project-link (fetch) origin super-project-link (push) longlv sub-project-link (fetch) longlv sub-project-link (push)

  • Commit git checkout develop git pull origin develop git checkout -b oLeVanLong_164392 git rebase develop git status git add . git commit -m "Bug #164390 [BookHodai] Fix bugs feedback" git commit --amend --no-edit git push long oLeVanLong_164390

  • Replace Commit git status git add . (git reset -> undo add) git commit --amend -m "Bug #164390 [BookHodai] Fix bugs feedback"

git push long oLeVanLong_164390 -f

  • Gop 2 commit git status git log --oneline -5 // Xem 5 log dau tien git reset HEAD~ // xoa commit trung dau tien git add . git commit --amend --no-edit git status // Se thay cac file thay doi cua commit da xoa git branch git push long oLeVanLong_164390 -f

  • Pick commit git cherry-pick 453e458 // add commit to my branch // Remove cherry pick git stash git reset --hard HEAD^ git stash pop -Delete branch

    • Remotely
    • git push origin --delete longlv_Ticket1
    • Local
    • git branch -d <branch_name>

//Rename banch

  1. Rename your local branch. If you are on the branch you want to rename:

git branch -m new-name If you are on a different branch:

git branch -m old-name new-name 2. Delete the old-name remote branch and push the new-name local branch.

git push origin :old-name new-name 3. Reset the upstream branch for the new-name local branch. Switch to the branch and then:

git push origin -u new-name

-Submodule git submodule add Now when you clone the project you simply need to init and update the submodule

git submodule init git submodule update Git 1.8.2 features a new option --remote git submodule update --init --recursive or git submodule update --remote --merge

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment