Connect your device to your computer over USB cable.
If necessary, unlock the device's bootloader using one of the following methods:
fastboot flashing unlock
For Pixel 2: To flash the bootloader, Pixel 2's bootloader must be updated to at least Oreo MR1's version first. This may be done by applying an over-the-air (OTA) update or sideloading a full OTA.
For Pixel 2 XL only with loader version prior to TMZ20a: the critical partitions may also need to be unlocked before flashing.
The unlock can be performed with this command, and should NOT be done on other devices:
fastboot flashing unlock_critical
The target device will show you a confirmation screen.
(This erases all data on the target device.)
Open a terminal and navigate to the unzipped system image directory.
Execute the flash-all script. This script installs the necessary bootloader, baseband firmware(s), and operating system.
Once the script finishes, your device reboots. You should now lock the bootloader for security if not need then that all. Congratulations.
Bootloader Locking in GOOGLE Pixel XL 2 phone
Start the device in fastboot mode.
fastboot flashing lock
Locking bootloader will wipe the data on some devices. After locking the bootloader, if you want to flash the device again, you must run fastboot OEM unlock again, which will wipe the data.