Toc
  1. quickly see
  2. install
    1. windows 10
    2. Ubuntu/Debian
  3. basic use
    1. create new repository
    2. clone existing repository
    3. Configure repository
    4. work with repository
      1. checkout
    5. Git GUI use
  4. prepare with Github
    1. Create SSH Key
    2. Configure ssh-agent
    3. Add SSH key to Github
  5. prepare with Gitee
    1. Create SSH Key
    2. Add SSH key to Gitee
  6. more about git
Toc
0 results found
MINGG

Created: 2021-05-28 09:09:58

Modified: 2021-7-29 12:09:56

Git installation and usage.

quickly see

details later, make it quick

ls -al ~/.ssh
ssh-keygen -t ed25519 -C "<personal code, like a email>" [-f ~/.ssh/gitee_id_ed25519]

eval `ssh-agent -s`
ssh-add -l
ssh-add <SSH private key>
ssh-agent -k

ssh -T git@github.com
ssh -T git@gitee.com

git --version

mkdir [<directory>]
cd [<directory>]
git init [<directory>]
git clone <repository> [<directory>]

git config --list
git config --global user.name MINGG2333
git config --global user.email 54434036+MINGG2333@users.noreply.github.com
git config user.email "{ID}+{username}@users.noreply.github.com"

git status -s
git log

touch README.md
cat README.md
git add README.md
git commit -m "first commit"

git remote -v
git remote add origin git@github.com:<name>/<repository>.git
git remote add origin2 git@gitee.com:<name>/<repository>.git
git remote rename origin oschina
git remote set-url origin 仓库地址
git remote rm origin2

git push -u origin2 master
git pull -u origin2 master

git branch -M main

git branch
git checkout master

git fetch origin2
git diff --stat main origin2/main

git submodule add <url> <directoty>
git rm --cached <object>

git clone --recursive https://github.com/RishabhMaheshwary/query-attack.git

# git lfs: An open source Git extension for versioning large files
curl -s https://packagecloud.io/install/repositories/github/git-lfs/script.deb.sh | sudo bash
sudo apt-get install git-lfs
git-lfs install
git lfs pull


git config --add core.filemode false

*origin, origin2 are personal names for repository

to clear commits, 清除github所有历史提交记录的方法 (ops-coffee.cn)

for private email, git - Error “Your push would publish a private email address” - Stack Overflow, then change email in ,

install

check your installation using command line( like Git CMD, Git Bash):

git --version

windows 10

official website:

Git for Windows or Git - Downloads (git-scm.com)

you can refer to( remember your installation directory of git if you want to set it as environment variable later):

Windows系统Git安装教程(详解Git安装过程)_IT技术实战-CSDN博客

*set {installation directory}\cmd\git.exe as environment variable in Path if you want to use it in other command line like cmd.exe

Ubuntu/Debian

For the latest stable Git version in Ubuntu/Debian:

sudo apt-get install git

basic use

you can create a new repository or clone a existing one

construction of a git repository

construction of a git repository (HEAD is the core, local repository)

create new repository

create a local repository(版本库), a directory of ‘.git’, in the ‘directory ‘ using Git Bash :

git init [<directory>]

image-20210528141522842

clone existing repository

clone a existing repository in ‘directory ‘ using Git Bash:

git clone <repository> [<directory>]

Configure repository

check your configuration:

git config --list

set your information for local repository before “commit”:

git config --global user.name "<name>"
git config --global user.email <email>

more configuration, refer to Git 创建仓库 | 菜鸟教程 (runoob.com)

work with repository

img

frequency use

more use, refer to Git 仓库基础操作 - Gitee, Git 基本操作 | 菜鸟教程 (runoob.com), Git 远程仓库(Github) | 菜鸟教程 (runoob.com), Git Gitee | 菜鸟教程 (runoob.com).

*you can place your remote repositories in Github, preparation see [prepare with Github](# prepare with Github).

checkout

refer to git checkout 命令详解,

Git GUI use

refer to 使用Git 总结-msysGit与GitHub 使用_荒野之鹰-CSDN博客 or Windows平台下Git的安装msysgit与配置_睡得香吃得好胆子大的专栏-CSDN博客

prepare with Github

configure your account SSH Key, refer to 使用 SSH 连接到 GitHub - GitHub Docs

Create SSH Key

check existing keys:

ls -al ~/.ssh

*”~/.ssh” is the default directory of SSH keys.

otherwise, create a SSH key for your device using Git Bash:

ssh-keygen -t [algorithm] -C "<personal code, like a email>"

*algorithm(optional): rsa [-b 4096], ed25519(recommend).

Configure ssh-agent

ssh-agent stores unencrypted keys in memory( for Unix-like OS) and communicates with SSH clients using a Unix domain socket

efasfs

ssh-agent principle

run ssh-agent using Git Bash:

# Windows
eval `ssh-agent -s`
# Linux
eval "$(ssh-agent -s)"

check keys loaded in the ssh-agent:

ssh-add -l

if none, add SSH private key to the ssh-agent:

ssh-add <SSH private key>

*SSH private key example: ~/.ssh/id_ed25519

switch off the agent using Git Bash, refer to ssh agent详解 - 知乎 (zhihu.com):

ssh-agent -k

*if not use agent, there maybe warnings, solution refer to: Win10 从零搭建Git环境_feng991254的专栏-CSDN博客 or win10 git环境搭建_ydf8525的专栏-CSDN博客

Add SSH key to Github

  1. open responding SSH public key with a editor like Notepad, then copy the contents of the .pub file to your clipboard,

*SSH public key example: ~/.ssh/id_ed25519.pub, so you can print it in line:

# windows & 
cat ~/.ssh/id_ed25519.pub
# Linux
sudo apt-get update
sudo apt-get install xclip
xclip -selection clipboard < ~/.ssh/id_ed25519.pub
  1. go into your own Github setting -> SSH and GPG keys, and create a new SSH key,

fggsagagwrg

then give a name of the key filling in the “title”, and paste the SSH public key contents into the “Key” field.

image-20210601135946523

  1. test SSH connection:
ssh -T git@github.com

if something wrong, baidu or google.

prepare with Gitee

configure your account SSH Key

Create SSH Key

check existing keys:

ls -al ~/.ssh

*”~/.ssh” is the default directory of SSH keys.

otherwise, create a SSH key for your device using Git Bash:

ssh-keygen -t [algorithm] -C "<personal code, like a email>"

*algorithm(optional): rsa [-b 4096], ed25519(recommend).

Add SSH key to Gitee

  1. open responding SSH public key with a editor like Notepad, then copy the contents of the .pub file to your clipboard,

*SSH public key example: ~/.ssh/id_ed25519.pub, so you can print it in line:

cat ~/.ssh/id_ed25519.pub
  1. go into your own Gitee setting -> SSH keys, then fill the blank and add a new SSH key: give a name of the key filling in the “title”, and paste the SSH public key contents into the “Key” field.
  2. test SSH connection:
ssh -T git@gitee.com

if something wrong, baidu or google.

more about git

谈谈 Git 存储原理及相关实现 - 知乎 (zhihu.com),

看完这篇还不会用Git,那我就哭了! - 知乎 (zhihu.com),

http://git.oschina.net/progit/,

https://www.liaoxuefeng.com/wiki/896043488029600/896067008724000,

https://gitee.com/help/articles/4104,

打赏
支付宝
微信
本文作者:MINGG
版权声明:本文首发于MINGG的博客,转载请注明出处!