Tangwx

Tangwx

博客网站

git commit command

Git Commit Command#

Commit Steps#

  1. Add all files in the current directory to the staging area
git add .
  1. Show the status of the working directory and the staging area
git status
  1. Add the contents of the staging area to the local repository
git commit -m "commit info"
  1. Specify the remote repository name and branch name
git push origin master

If an error occurs

$ git push origin master
To gitee.com:tanggitee/embedded-learning-notes.git
 ! [rejected]        master -> master (non-fast-forward)
error: failed to push some refs to 'gitee.com:tanggitee/embedded-learning-notes.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

You can add the following command in steps 3 and 4 to force update the code from the remote repository to the current branch.

git pull --rebase origin master

Pushing a Project to Gitee for the First Time#

Create an Account#

Create a Gitee account. Gitee is fast in China.

Install Git Locally#

Go to Git and download Git to your local machine based on your operating system.

SSH Key#

Generate a Key Locally#

Right-click on your desktop and open your git bash. When using Git for the first time, you need to generate an SSH key first.

ssh-keygen -t rsa -C "your_email"

The generated key is usually located in the .ssh directory under your operating system user.

Inform the Local System#

Tell the local system about the key.

ssh-add ~/.ssh/id_rsa

(If you encounter Could not open a connection to your authentication agent., execute ssh-agent bash first.)

View the Generated Public Key#

cat ~/.ssh/id_rsa.pub

Upload the Public Key#

Copy the public key and paste it into the SSH public key page of your Gitee account. Using an SSH public key allows you to use a secure connection when communicating between your computer and Gitee (use the SSH address for Git's Remote).

Configure User#

When opening git bash, configure:

git config --global user.name "your_Name"
git config --global user.email"your_email"

Initialize Local Git Repository#

git init

After executing this command, a .git folder will be added.

Add Changed Files#

git add .  // Add all changed files

Commit Files#

git commmit -am "message" // Commit all changed files

Add Remote Address#

git remote add origin [email protected]:your_gitee_username/repository_name.git

SSH Test#

ssh -T [email protected]

If it displays Welcome to Gitee.com, your_username!, it means SSH is correct.

Possible Errors#

If fatal: remote origin already exists. appears, execute git remote rm origin.

Initial Commit#

The first commit may encounter the following error:

error: failed to push some refs to 'https://gitee.com/tomFat/interview.git'

So, execute git pull before committing.

Merge Two Version Repositories#

git pull origin master --allow-unrelated-histories

Push to Github or Gitee#

git push -u origin master 
or git push your_gitee_repository_name master  # Push to a specific repository's master branch
or git push -u origin master -f   # Force push

[Gitee] Local Push Succeeds, but Does Not Contribute to Contribution Value (Resolved, same for Github and Gitlab)#

In the past few days, due to some requirements related to Gitee and Github, I made some configuration changes, which caused the local code to be pushed to the environment, but it did not contribute (the grid did not light up), which was confusing. I solved this problem through some operations and recorded it.


Actually, the configuration information is incorrect. Just change your configuration information. If the method below still cannot solve your problem, please continue reading.

// Check
git config --global -l
// Set
git config --global user.name "your-username"
git config --global user.email "[email protected]"
12345

Note: In Personal Settings, there is an email in the Profile, and there is also an email below called Emails. Please use the one below.


Git Configuration Levels have the following 3 types:#
  1. Repository level local [highest priority]

  2. User level global [second highest priority]

  3. System level system [lowest priority]

git config --list to view all configuration information, in order: system level, user level, repository level

Common Git Config Configuration Options#
git config -e Edit configuration file 
- git config --local -e Edit repository-level configuration file
- git config --global -e Edit user-level configuration file
- git config --system -e Edit system-level configuration file

git config Modify configuration item
- git config --global user.email "[email protected]"
- git config --global user.name "Your Name"
- 
git config Add configuration item 
- git config [--local|--global|--system] --add section.key value

git config Get configuration item 
- git config [--local|--global|--system] --get section.key

git config Delete configuration item 
- git config [--local|--global|--system] --unset section.key
Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.