Add gitee (code cloud) connection to your project - a Git note

1. Install Git

Go to Git official website( https://git-scm.com/ )Download Git and click exe to install mindlessly. If you want to change the installation path, please follow the principle by yourself.

2. Configure Git

Configure your global Git user name and mailbox

git config --global user.name  "Jajison"
git config --global user.email "1392789997@qq.com"

In fact, the global configuration is only saved in a file in the local directory.

Find your path: drive C - user - user name, find gitconfig file.

For example, my:

C:\Users\Jajison\.gitconfig

Open to find your configuration saved here

3. Go to gitee (official website) to register an account and set up SSH

If you just save different versions of your code in the cloud for you, GitHub is a good choice considering that GitHub can't go up occasionally.

After successful registration, enter the personal Center - SSH public key, and you can see

We need to create an SSH public key on our computer.

Find your path: drive C - user - user name, such as mine

C:\Users\Jajison\.ssh

Without this ssh folder, then create a new file and add it

mkdir .shh

If this folder, you have not created an SSH public key.

Now you can create your SSH public key with Git command

ssh-keygen -t rsa

Git will ask whether to set a password for the private key. You can directly press Enter to skip these.

After completion, it will be displayed in C: \ users \ jajason \ Two new files are generated under SSH: id_rsa.pub and id_rsa.

Open id_rsa.pub, copy, is your SSH public key

Paste it on Gitee and your title will be automatically generated. Confirm and submit.

4. Connect your local project to the remote warehouse

4.1 the first method (recommended)

Create a new warehouse in Gitee

Click clone / download to copy the HTTPS connection. For example, my is https://gitee.com/jajison/git-study.git .

Select any path locally and enter git command

git clone https://gitee.com/jajison/git-study.git

You can see that your warehouse has been downloaded locally, and the local project is connected to the remote warehouse.

Now you can add commit push and other operations

If you want to turn a local project into a connection to the warehouse you created in Gitee, you can connect the empty warehouse before establishment, download several files locally and copy them directly to your local project path

That is - copy these files directly to your local project path

Now your local project is connected to the remote warehouse.

If this is a Java project, you can open it in the IDEA (the IDE of JetBrains is roughly the same).

You will see the button related to Git operation in the upper right corner.

You can use this button to perform add commit push and other operations.

But I still recommend that you use the Git command.

4.2 use the functions of IDE

Obviously, you can connect your local projects to your Gitee by using the functions of the IDE

Download Gitee plugin

Log in to your Git or Gitee here

Perform relevant operations in Git in the main menu.

5. Some common Git commands (copied from the official website)

5.1 warehouse

# Create a Git code base in the current directory
$ git init

# Create a new directory and initialize it as a Git code base
$ git init [project-name]

# Download a project and its entire code history
$ git clone [url]

5.2 configuration

# Displays the current Git configuration
$ git config --list

# Edit Git profile
$ git config -e [--global]

# Set user information when submitting code
$ git config [--global] user.name "[name]"
$ git config [--global] user.email "[email address]"

5.3 adding / deleting files

# Adds the specified file to the staging area
$ git add [file1] [file2] ...

# Adds the specified directory to the staging area, including subdirectories
$ git add [dir]

# Add all files in the current directory to the staging area
$ git add .

# Confirmation is required before adding each change
# For multiple changes in the same file, it can be submitted in batches
$ git add -p

# Delete the workspace file and put the deletion into the staging area
$ git rm [file1] [file2] ...

# Stops tracking the specified file, but the file remains in the workspace
$ git rm --cached [file]

# Rename the file and put the rename in the staging area
$ git mv [file-original] [file-renamed]

5.4 code submission

# Submit staging area to warehouse area
$ git commit -m [message]

# Submit the specified files in the temporary storage area to the warehouse area
$ git commit [file1] [file2] ... -m [message]

# Submit the changes in the workspace since the last commit and go directly to the warehouse area
$ git commit -a

# Show all diff information when submitting
$ git commit -v

# Use a new commit instead of the last commit
# If there are no new changes in the code, it is used to rewrite the submission information of the last commit
$ git commit --amend -m [message]

# Redo the last commit and include new changes to the specified file
$ git commit --amend [file1] [file2] ...

5.5 branch

# List all local branches
$ git branch

# List all remote branches
$ git branch -r

# List all local and remote branches
$ git branch -a

# Create a new branch, but still stay in the current branch
$ git branch [branch-name]

# Create a new branch and switch to it
$ git checkout -b [branch]

# Create a new branch and point to the specified commit
$ git branch [branch] [commit]

# Create a new branch and establish a tracking relationship with the specified remote branch
$ git branch --track [branch] [remote-branch]

# Switch to the specified branch and update the workspace
$ git checkout [branch-name]

# Switch to previous branch
$ git checkout -

# Establish a tracking relationship between an existing branch and a specified remote branch
$ git branch --set-upstream [branch] [remote-branch]

# Merge the specified branch to the current branch
$ git merge [branch]

# Select a commit to merge into the current branch
$ git cherry-pick [commit]

# Delete branch
$ git branch -d [branch-name]

# Delete remote branch
$ git push origin --delete [branch-name]
$ git branch -dr [remote/branch]

5.6 labels

# List all tag s
$ git tag

# Create a new tag in the current commit
$ git tag [tag]

# Create a new tag and specify the commit
$ git tag [tag] [commit]

# Delete local tag
$ git tag -d [tag]

# Delete remote tag
$ git push origin :refs/tags/[tagName]

# View tag information
$ git show [tag]

# Submit the specified tag
$ git push [remote] [tag]

# Submit all tag s
$ git push [remote] --tags

# Create a new branch to point to a tag
$ git checkout -b [branch] [tag]

5.7 viewing information

# Show changed documents
$ git status

# Displays the version history of the current branch
$ git log

# Displays the commit history and the files that change each time a commit occurs
$ git log --stat

# Search submission history according to keywords
$ git log -S [keyword]

# All changes after a commit are displayed, and each commit occupies one line
$ git log [tag] HEAD --pretty=format:%s

# Display all changes after a commit, and its "submission description" must meet the search criteria
$ git log [tag] HEAD --grep feature

# Displays the version history of a file, including file renaming
$ git log --follow [file]
$ git whatchanged [file]

# Displays each diff related to the specified file
$ git log -p [file]

# Show last 5 submissions
$ git log -5 --pretty --oneline

# Displays all submitted users, sorted by submission times
$ git shortlog -sn

# Displays who modified the specified file and when
$ git blame [file]

# Show differences between staging and workspace
$ git diff

# Displays the difference between the staging area and the previous commit
$ git diff --cached [file]

# Displays the difference between the workspace and the latest commit of the current branch
$ git diff HEAD

# Displays the difference between two submissions
$ git diff [first-branch]...[second-branch]

# Show how many lines of code you wrote today
$ git diff --shortstat "@{0 day ago}"

# Displays the metadata and content changes of a submission
$ git show [commit]

# Displays the files that have changed in a submission
$ git show --name-only [commit]

# Displays the contents of a file at the time of a submission
$ git show [commit]:[filename]

# Displays the most recent commits of the current branch
$ git reflog

5.7 remote synchronization

# Download all changes of remote warehouse
$ git fetch [remote]

# Show all remote warehouses
$ git remote -v

# Displays information about a remote warehouse
$ git remote show [remote]

# Add a new remote warehouse and name it
$ git remote add [shortname] [url]

# Retrieve the changes of the remote warehouse and merge with the local branch
$ git pull [remote] [branch]

# Upload specified local branch to remote warehouse
$ git push [remote] [branch]

# Forcibly push the current branch to the remote warehouse, even if there is a conflict
$ git push [remote] --force

# Push all branches to remote warehouse
$ git push [remote] --all

5.8 revocation

# Restore the specified files in the staging area to the workspace
$ git checkout [file]

# commit and restore files to a designated workspace
$ git checkout [commit] [file]

# Restore all files in the staging area to the workspace
$ git checkout .

# Reset the specified file in the staging area, which is consistent with the last commit, but the workspace remains unchanged
$ git reset [file]

# The staging area is consistent with the previous commit
$ git reset --hard

# Reset the pointer of the current branch to the specified commit, and reset the staging area at the same time, but the workspace remains unchanged
$ git reset [commit]

# Reset the HEAD of the current branch to the specified commit, and reset the staging area and workspace at the same time, which is consistent with the specified commit
$ git reset --hard [commit]

# Reset the current HEAD to the specified commit, but leave the staging area and workspace unchanged
$ git reset --keep [commit]

# Create a new commit to revoke the specified commit
# All changes in the latter will be offset by the former and applied to the current branch
$ git revert [commit]

Temporarily remove uncommitted changes and move in later
$ git stash
$ git stash pop

5.9 others

# Generate a compressed package for publishing
$ git archive

Keywords: git

Added by Archangel915 on Sat, 19 Feb 2022 02:56:57 +0200