Configure git
1. First create the ssh key locally;
ssh-keygen -t rsa -C "Email registered on github" //(Enter all the way)
2. Enter the c:/Users/xxxx_000/.ssh/ directory, open id_rsa.pub file, select all to copy the public key content
3. Configure the account
git config --global user.name "username" //Set the username
git config --global user.email "github_Email" //Set the email address
4. Test Whether the ssh keys are set successfully
ssh -T [email protected]
If it is the first time, it will prompt whether to continue, enter yes and you will see: You've successfully authenticated, but GitHub does not provide shell access . This means that you have successfully connected to github.
5. github configuration public key
-------------------------------------------- -------------------------------------------------
Situation 1: The remote warehouse has not submitted code (first create a github warehouse as a warehouse for remote management code)
mkdir gitTest //Create a new local directory as a warehouse (simply put, the place to put the code)
cd gitTest //Enter the folder
git init //Initialize the local repository
git add -A / git add . //Add all changes to the staging area
git commit -m "remark information" //Submit to the staging area and remarks such as what function has been done to resolve conflicts and so on
git remote add origin warehouse name (usually ssh) //Associate with remote warehouse
git push -u origin master //Because the newly created remote warehouse is empty, you need to add the -u parameter. After the content is available in the remote warehouse, you only need to git push origin when uploading content from the local library next time master
There is a pit to pay attention to here, that is, when you create a remote warehouse, if you check Initialize this repository with a README (that is, when you create a warehouse, a README file is automatically created for you)
to push the contents of the local warehouse to the remote warehouse. It will report a failed to push some refs to https://github.com/xx/xx.git
We can execute git pull --rebase origin master //Pull the remote file to overwrite the local one, and then upload it
git push origin master -f //Forcibly upload the local to the remote and overwrite the remote (generally not recommended)
------------------------- -------------------------------------------------- ------------------
Situation 2: The remote code has been established and the project code has been submitted
git remote add origin warehouse address //Associate remote warehouse
git push - u origin master //Push the local master branch to the origin host, and specify origin as the default host;
------------------------- -------------------------------------------------- ------------------
Scenario 3: Pull the remote branch
git clone warehouse address //Clone the default master branch of the remote warehouse;
git branch -a //how many branches the current master has
git checkout -b xx branch name origin/xx branch name //create a new branch locally that is consistent with the remote; git pull origin xx branch name//pull branch code (both ways are possible)
------ -------------------------------------------------- -------------------------------------
Four. The more useful commands commonly used by
git git status // View current status
git add . or git add -A // commit all changes
git commit -m "Remark information such as (what function, what modification code, merge conflict resolution, etc.)"
git merge branch name // merge branch
git branch -d branch name // delete branch
git branch -a //how many branches the current master has
git checkout -b xx branch name origin/xx branch name //Create a new branch locally and the remote one;
git checkout -b xx branch name // create a new branch and switch to it
git branch branch name //switch branch command
git clone repository address //clone code
git diff // preview the difference
git tag 1.0.0 1b2e1d63ff //Tagging 1b2e1d63ff is the first 10 characters of the commit ID you want to tag (it can be less). Commit IDs can be obtained with the following command: git log
git checkout --filename //abandon current file changes