web123456

The operation process is carried out by pushing the local branch to the github branch:

1. Preparation phase: Configure SSH keys

  1. Configure Git user information

    1. git config --global "123456"
    2. git config --global "yyy123@"
    3. git config --list
  2. Generate SSH key

    ssh-keygen -t rsa -C "yy123@"

    When asked for the save location, press Enter to accept the default location. Then enter your password twice.

  3. Confirm the key location

    1. cd ~/.ssh
    2. ls
    3. cat id_rsa.pub

    Copy the output public key and add it to yourGitLabThe SSH keys settings for the account.

2. Operation process

  1. Cloning the repository
    git clone   -b  feature-branch
    This clons the repository and switches directly to the specified branch, with the corresponding replacement on it.
  2. Switch or create a branch

1. Switch branches

        cd your_project
        git checkout <branch-name>

2. Create a new branch and switch

cd your_project   Enter the project

git branch  View the current branch

git branch <branch-name>  Create branch

git checkout <branch-name>  Switch branches (can be displayed on the terminal)

1. If you want to switch to another branch, you can use the following command: git checkout <branch-name>
2. If you want to create a new branch based on an existing branch and switch to the new branch immediately, you can use:
git checkout -b <new-branch-name> <existing-branch-name>
3. If you want to restore the file to the state of the last commit, you can execute: app_new.py
git checkout app_new.py

3. Update the code

Delete the old code and keep the .git directory
Delete the code cloned above, leaving only.gitTable of contents. Delete all files and subdirectories, but keep.gitTable of contents. Then copy your project to that folder.

4. Add and submit changes

  1. Add changes

    1. git add .
    2. # Or add a specific file
    3. git add your_file.py
  2. Submit changes

    git commit -m "Add detailed description of what you changed"

5. Push changes to remote repository

  1. Push changes
    git push origin <your-branch>

Create a merge request

On GitLab, create a merge request (Merge)Request) to merge your branch into the main branch.

About Listing Branches

  • List remote branches
    git branch -r
  • List all branches (including local and remote)
    git branch -a

3. After you change the code, submitting changes to the Git repository usually involves the following steps:

Step 1: Check for changes

First, usegit statusThe command checks for changes in your current working directory:

git status

This lists all changes that have not been staged, including new files, modified files and deleted files.

Step 2: Save changes

For changes you want to include in this submission, you need to usegit addCommand to temporarily save it. You can choose to stage all changes, or just stage specific files:

  • Save all changes
    git add .

    This adds all modified files, new files and deleted files in the working directory to the temporary storage area.

  • Stories specific files
    git add path/to/your/file

    Willpath/to/your/fileReplace with the file path you want to temporarily save.

Step 3: Submit changes

After temporary storage of changes, usegit commitThe command creates a new commit:

git commit -m "Your commit message"

Enter your submission information in double quotes to describe what changes you made. A good submission should be concise and clear, describing the purpose and content of the change.

Step 4: Push changes

After submitting the changes, usegit pushCommand pushes your commit to the remote repository:

git push origin <branch-name>

Will<branch-name>Replace with the name of your current branch.

Example

Suppose you modified a nametrain_net.pyThe following is the complete submission and push process:

  1. # Check for changes
  2. git status
  3. # Save changes
  4. git add train_net.py
  5. # Submit changes
  6. git commit -m "modify train_net.py"
  7. # Push changes to remote repository
  8. git push origin Your branch

If you have modified multiple files, or added or deleted files, you can reuse themgit addCommand to save all relevant changes and submit them in one go.

4. If you want to delete certain files in the Git branch, you can follow the following steps:

Make sure you are already on the target branch, and the next step is to delete the file you want to remove. Suppose you want to delete the nameYou can follow the following steps for the file:

Step 1: Confirm the file exists

First, make sure that the file does exist in your working directory:

ls path/to/your/directory
Step 2: Delete the file

Delete files in the local working directory:

rm path/to/your/

Or inWindowsUsed in the system:

del path\to\your\example.txt
Step 3: Usegit rmOrder

Remove files from Git trace:

git rm path/to/your/

This will mark the file as deleted, ready to go fromVersion controlRemoved in .

Step 4: Submit changes

Now you can submit changes to delete the file:

git commit -m "Delete  from  Your branch"

Make sure you clearly state the changes you made in the commit message.

Step 5: Push changes to remote repository

Finally, push your changes to the remote repository:

git push origin Your branch

This will sync changes to your deleted files in Your branch branch to the remote repository.

Through the above steps, you can safely delete files in Your branch branch and submit changes to the repository. If the file has been deleted, but you still see it in the repository, it may be because you haven't committed and pushed those changes yet. Make sure to perform all steps, especiallygit rmgit commitandgit push。