TungNT (Blue)

tungnt.blue@gmail.com

User Tools

Site Tools


development:system:git

This is an old revision of the document!


Git

Cài đặt và cấu hình

$ apt-get install git
$ git config --global user.name "TungNT"
$ git config --global user.email "tungnt.blue@gmail.com"

Tạo SSH Key

$ ssh-keygen -t rsa -b 4096 -C "tungnt.blue@gmail.com"

Tạo nhiều tài khoản ssh key

$ ssh-keygen -t rsa -b 4096 -C “tungnt.blue@gmail.com”
Generating public/private rsa key pair.
Enter file in which to save the key (/var/root/.ssh/id_rsa): id_rsa_tungntblue
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in id_rsa_tungntblue.
Your public key has been saved in id_rsa_tungntblue.pub.
$ ssh-keygen -t rsa -b 4096 -C “nguyentung@mobgame.vn”
Generating public/private rsa key pair.
Enter file in which to save the key (/var/root/.ssh/id_rsa): id_rsa_nguyentung
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in id_rsa_nguyentung.
Your public key has been saved in id_rsa_nguyentung.pub.
The key fingerprint is:
$ ls -la /var/root/.ssh/
-rw-------   1 root  wheel  3243 Nov  1 10:26 id_rsa
-rw-r--r--   1 root  wheel   747 Nov  1 10:26 id_rsa.pub
-rw-------   1 root  wheel  3243 Nov  1 22:24 id_rsa_nguyentung
-rw-r--r--   1 root  wheel   753 Nov  1 22:24 id_rsa_nguyentung.pub
-rw-------   1 root  wheel  3243 Nov  1 22:21 id_rsa_tungntblue
-rw-r--r--   1 root  wheel   753 Nov  1 22:21 id_rsa_tungntblue.pub
-rw-r--r--   1 root  wheel  5036 Nov  1 10:23 known_hosts

Add các key:

$ ssh-add ~/.ssh/id_rsa_tungntblue
Identity added: /var/root/.ssh/id_rsa_tungntblue (/var/root/.ssh/id_rsa_tungntblue)
$ ssh-add ~/.ssh/id_rsa_nguyentung
Identity added: /var/root/.ssh/id_rsa_nguyentung (/var/root/.ssh/id_rsa_nguyentung)
$ ssh-add -l
4096 SHA256:HntA0FUgaD0ELTaHSU/h0SfTAKVPkJ9xEjnP6aXyCvM /var/root/.ssh/id_rsa_tungntblue (RSA)
4096 SHA256:2cJDMSnLCJPnd6K4cIdjmI58FwJ/X7u4Wrml4S8ulHw /var/root/.ssh/id_rsa_nguyentung (RSA)

Tạo command add key:

$ vim gi.sh
#! /bin/bash
  
ssh-add /var/root/.ssh/id_rsa_tungntblue
ssh-add /var/root/.ssh/id_rsa_tungnt9pay
ssh-add /var/root/.ssh/id_rsa_nguyentung

ssh-add -l

$ chmod +x gi.sh
$ ln -s gi.sh /usr/local/bin/gi
$ gi

Cấu hình Host sử dụng key:

$ vim ~/.ssh/config
Host bitbucket.org
HostName bitbucket.org
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa_tungntblue

Host github.com
HostName github.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa_tungntblue

Host git.mobgame.mobi
HostName mobgame.mobi
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa_nguyentung

Khởi tạo Git

$ git init
$ git add .
$ git commit -am 'Init source'
$ git remote add origin git@github.com:abc/xyz.git
$ git remote -v
$ git push origin master

Branch

$ git checkout -b dev
$ git checkout -b dev master

$ git branch -D dev

$ git checkout [branch_name] -- [file_path]

$ git diff [branch_1] [branch_2]
$ git diff --name-only [branch_1] [branch_2]
$ git diff [branch_1] [branch_2] --file
$ git diff --name-only master release/complete > diff_master_with_release_complete.txt

Xem log

$ git reflog
$ git reflog master

Sửa commit message cuối cùng

$ git commit --amend

$ git reset --hard [commit_version]

Submodule

git submodule add {GIT_URL} {DIR_PATH}

https://www.atlassian.com/git/tutorials/git-submodule

Một số lỗi có thể gặp

"Warning: the ECDSA host key for 'github.com' differs from the key for the IP address" issue

development/system/git.1723450411.txt.gz · Last modified: 2024/08/12 08:13 by tungnt

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki