Git - Github - Gitlab notes
Posted on 28/11/2018, in Infomation Technology.This note is used for my daily working routine with git.
-
Set the information
git config --global user.name "Dinh Anh Thi" git config --global user.email "[email protected]"
-
Save github account as default
git config credential.helper store
then
git pull
for the first time input. - Create a repository:
git init <repo-name>
- Clone a repo (using HTTPS method):
git clone <repo-link>
- Open git gui :
git gui
orgitk
(they are different) - Check the status:
git status
,git log --oneline --graph --color --all --decorate
- Discard the change:
git checkout .
- Temporarily check a commit:
git checkout <commitID>
, if the work’s done, just check out back to the current working branch. - Tạo nhánh mới:
git checkout -b <ten-nhanh> # tạo và chuyển tới nhánh mới
git branch <ten-nhanh> # tạo nhánh mới
- Xóa nhánh:
git branch -d <ten-nhanh> # xóa nhánh local
git push origin :<tên-nhánh> # xóa nhánh remote
- Liệt kê danh sách các nhánh
git branch # local
git branch -a # local & global
-
Merge sub branch to master and replace master branch
git checkout <nhanh> git merge -s ours master git checkout master git merge <nhanh>
-
Working with branches
- Compare 2 branches:
git diff <src-branch> <compared-branch>
- Delete:
git branch -d <branch>
- Delete (remove):
git push --delete origin <branch>
- Add description:
git branch --edit-description
(if you wanna exit Vim, press ESC then type:q
to quit or:wq
to quit and write)
- Compare 2 branches:
-
Error:
Could not resolve host: github.com
git config --global --unset http.proxy git config --global --unset https.proxy
-
Copy/update a folder from another branch to current branch. Suppose that we wanna copy folder abc from branch test5 to current brach other-machine
git checkout other-machine # go to current branch git checkout test5 path/to/abc git status # to see the change
-
Pull from remote and replace everything from remote to local
git fetch origin git reset --hard origin/master