【Commonly used! 】How to upload server code to GitHub and update it

How to upload server code to GitHub and update it

== 1. Create a new code repository in GitHub ==

== 2. Preparation==
git version # Check whether there is git, if not, download it
git init # Initialize git git remote -v # Check whether the addition is successful< /span> git remote add origin https://github.com/xxx/xxx.git # Add remote address git config --global user.name “xxx ”
git config --global user.email “[email protected]” # (Log in) Tell Git who you are


git remote set-url origin https://github.com/lunbubu/AFL_VEC2.git # Reset url

== 3. Upload code==
git add .# The code of the current project will be added to the cache area
git commit -m 'initial submit' # Commit to the local warehouse [ The color of the directory on the left will change to normal] ['initial submit' is the remark information]
git push origin master# Push the local master branch to the master branch of the origin host. The general form is git push <remote host name> <local branch name> <remote branch name>. git push origin master: origin is the remote host, and master represents the abbreviation of the master branch on the remote server and the local branch. The branch name can be modified.

git branch -r # View the remote branch name
git branch # View the local branch name
git push # If the current branch has only one remote Branch, then the host name can be omitted, such as git push

git push origin HEAD # Only push the latest commit
git push origin # The commit specified by push is the hash value of the commit to be pushed

In summary, there are three operations: add, commit, push

== Using a branch means you can detach from the main development line and continue working without affecting the main line==
git branch -M main # Rename the branch , using -M means forced renaming
git branch #View all local branches
git branch -r #View all remote branches
git pull origin main # means pulling the master branch of the remote origin host and merging it with the local current branch

git status # View the current git status

working tree (working directory), Index (temporary storage area)

== If there is an error in the code of a commit, how to undo the commit without affecting the local code? ==
git log # Print commit log
git reset --soft [commit version number] # Roll back to this version of commit
git status # Check the current git status
git log # Check the commit status again to see if it has been rolled back
Then just execute add, commit, and push

== May need to be used in conjunction with deleting the cache area
git reflog # View the operation log, HEAD pointer
git log # View all local commits< /span> git rm -r --cached data/ # Delete all contents in the data folder of the cache area< /span>
git ls-files # View the contents of the cache area

git reset --hard HEAD^ # tmd Never use this command! ! ! ! ! Undoing a commit will also undo the changes in the working tree. Reset the staging area and workspace and completely roll back to a certain version.

== How to restore the code if git reset --hard happens accidentally? ==
The premise is git commit, otherwise this method will not work

git fsck --lost-found # Find traces of committed code. What follows dangling commit is code
git show [string after dangling commit] # Check which one It’s the code you deleted yourself
git rebase [string after dangling commit] # Restored

== Already have a remote warehouse, how to change a remote warehouse==
git remote rm origin # Delete the original one first
git remote add origin [email protected]:your_username/your_repository.git

Notice

To operate git in the terminal, you must enter the folder where it is located. Only when the current folder is uploaded to GitHub can there be git operation. You can use thegit status command to view the current status:

Insert image description here
This means that the current folder is not git transferred to the warehouse.

Insert image description here
This is what exists.

Guess you like

Origin blog.csdn.net/summertime1234/article/details/133778141