If you have a product attribute and what to assign it to a single attribute set, it's easy to do via Magento 2 Admin Panel > Stores > Attributes > Attribute Set.
But what if you need to assign it to all your attribute sets? What if you have 50+ or ever 100+ attribute sets? It can be time costly.

So what you can do, is to create a simple script that will do all job for you.

1. Create a PHP file "myscript.php" in your Magento 2 root directory.

2. Insert the code:

<?php

error_reporting(E_ALL);
ini_set('display_errors', 1);
$ATTRIBUTE_CODE = 'my_attribute';
$ATTRIBUTE_GROUP = 'General';
use Magento\Framework\App\Bootstrap;
require __DIR__ . '/app/bootstrap.php';
$bootstrap = Bootstrap::create(BP, $_SERVER);
$objectManager = $bootstrap->getObjectManager();
$state = $objectManager->get(Magento\Framework\App\State::class);
$state->setAreaCode('adminhtml');

/* Attribute assign logic */ $eavSetup = $objectManager->create(\Magento\Eav\Setup\EavSetup::class);
$config = $objectManager->get(\Magento\Catalog\Model\Config::class);
$attributeManagement = $objectManager->get(\Magento\Eav\Api\AttributeManagementInterface::class);
$entityTypeId = $eavSetup->getEntityTypeId(\Magento\Catalog\Model\Product::ENTITY);
$attributeSetIds = $eavSetup->getAllAttributeSetIds($entityTypeId);
foreach ($attributeSetIds as $attributeSetId) {
    if ($attributeSetId) {
        $group_id = $config->getAttributeGroupId($attributeSetId, $ATTRIBUTE_GROUP);
        $attributeManagement->assign(
            'catalog_product',
            $attributeSetId,
            $group_id,
            $ATTRIBUTE_CODE,
            999
       );
    }
}

3. Change the value for $ATTRIBUTE_CODE and $ATTRIBUTE_GROUP.

4. Save the file.

5. Run CLI command:

php myscript.php

6. Once is done, please remove the myscript.php file or make it unavailable from the web.