GIT Remote Operation
1. Create an SSH key
(1) How to generate:
1, run ssh-keygen -t rsa-b 4096-c in cmder
2. Keep pressing the space until no prompt is prompted
3. Run cat to open id_rsa.pub to obtain the public key content
4. Open GitHub and enter the public key on the Settings page
(2) How to test the successful pairing:
Run SSH -t [email protected] in cmder and type yes and press Enter to ask yes/no
2. Upload local warehouse to GitHub
(1) Create a GitHub Repo, copy its SSH address, copy the code in the page, and do not change the rest
1.Git remote add origin git@xxxxxx
Add the remote repository address locally. Origin is the default name of the remote repository. You are not advised to change the name
Do not use https:// addresses, as passwords need to be changed each time
2.git push -u origin master
Push local master to branch to master branch of remote Origin
If you are prompted to git pull, git pull
① Git pull is used to merge a remote branch into a local branch. If the remote branch has not been updated, you can ignore git pull
②-u origin master, set the upstream branch, no longer set the upstream branch, directly git pull; git push
(2) open the code directory to be uploaded in vscode, create a terminal, paste the copied code, and upload a branch of the local warehouse
(3) How to upload other branches
Git push origin x:x
Git Checkout x
git push -u origin x
Third, download the remote warehouse to the local
Git clone git@xxx[target path]
Git clone usage
Git clone git@? /xxx.git
Git is a local repository, usually followed by CD XXX
Git clone git@? /xxx.git yyy
The yyy directory will be created locally. Remember to CD YYy
Git clone git@? /xxx.git .
The last character is a dot, note the space
Instead of creating a new directory, use the current directory to hold your code and.git, preferably empty
Upload to two remote warehouses
Application: Upload to Github and Gitee in China
git remote add repo2 git@xxx
git push -u repo2 master
Use bash alias to simplify commands
(1) touch ~/.bashrc
(2)
echo ‘alias ga=”git add”‘>> ~/.bashrc
echo ‘alias gc=”git commit -v”‘>> ~/.bashrc
echo ‘alias gl=”git pull”‘>> ~/.bashrc
echo ‘alias gp=”git push”‘>> ~/.bashrc
echo ‘alias gco=”git checkout”‘>> ~/.bashrc
echo ‘alias gst=”git status -sb”‘>> ~/.bashrc
(3) Then restart the command line or run source ~/.bashrc
Seven, git stash
Temporarily hide code in a space that needs to be pulled out with a Git Stash pop